views:

342

answers:

3
#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;

}
+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
At a guess, the matching close brace should go above the `//multiply(b)` comment.
Donal Fellows
A: 

You forgot the curly braces around case statements after switch.

Jasmeet
+2  A: 

You need braces for your switch:

switch (...)
{  // your forgot this
    ...
}  // and this
R Samuel Klatchko