#include <iostream>
#include <string>
using namespace std;
//void multiply(int b);
int main()
{
float total = 0;
float b = 0;
cout << "Enter number: " << endl;
cin >> b;
char TorD;
cout << "Would you like to times (*), divide (/), add (+) or minus (-) this number?" << endl;
cin >> TorD;
switch (TorD)
case '*' :
{
int c=0;
cout << "by how many?" << endl;
cin >> c;
total = b * c;
cout << b << " * " << c << " = " << total << endl;
}
break;
case '/' :
{
int c=0;
cout << "by how many?" << endl;
cin >> c;
total = b / c;
cout << b << " / " << c << " = " << total << endl;
}
break;
case '+' :
{
int c=0;
cout << "by how many?" << endl;
cin >> c;
total = b + c;
cout << b << " + " << c << " = " << total << endl;
}
break;
case '-' :
{
int c=0;
cout << "by how many?" << endl;
cin >> c;
total = b - c;
cout << b << " - " << c << " = " << total << endl;
}
break;
default:
cout << "You did not correctly enter /, *, +, or - !!" << endl;
//multiply(b);
system("pause");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
你失踪后的开括号switch (TorD),所以"休息"是外界的任何声明,从突破(即突破了是一个循环或开关内部,它的东西打出来的).switch语句应如下所示:
switch (TorD) {
case '*': {
// ...
}
break;
case '/': {
// ...
}
break;
// ...and so on.
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9962 次 |
| 最近记录: |