Switch Statement C++ - error C2046: illegal case, error C2043: illegal break
- by user318095
#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;
}