#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;
}
views:
342answers:
3
+9
A:
You're missing the open brace after the switch (TorD)
, so the 'break' is outside any statement to break from (i.e. a break has to be inside a loop or switch so it has something to break out of). The switch statement should look like:
switch (TorD) {
case '*': {
// ...
}
break;
case '/': {
// ...
}
break;
// ...and so on.
}
Jerry Coffin
2010-04-16 00:00:20
At a guess, the matching close brace should go above the `//multiply(b)` comment.
Donal Fellows
2010-05-09 05:11:25
+2
A:
You need braces for your switch:
switch (...)
{ // your forgot this
...
} // and this
R Samuel Klatchko
2010-04-16 00:00:48