#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;
}
答案 0 :(得分:8)
你在switch (TorD)
之后错过了开放式大括号,所以'break'超出了任何要断开的语句(即,有在一个循环或开关内的断点)它有一些东西可以突破)。 switch语句应如下所示:
switch (TorD) {
case '*': {
// ...
}
break;
case '/': {
// ...
}
break;
// ...and so on.
}
答案 1 :(得分:2)
您的开关需要大括号:
switch (...)
{ // your forgot this
...
} // and this
答案 2 :(得分:0)
切换后你忘记了case语句周围的花括号。