2010-04-15 2 views
0
#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; 

} 

답변

8
당신은 switch (TorD) 후 열린 중괄호를 놓치고

, 그래서 '휴식'(즉, 휴식 이 가지고에서 휴식 어떤 문 밖에은 루프 또는 스위치 내부에 있으므로 빠져 나올 항목이 있습니다.) switch 문은 다음과 같아야합니다.

switch (TorD) { 
    case '*': { 
     // ... 
    } 
    break; 
    case '/': { 
     // ... 
    } 
    break; 

    // ...and so on. 
} 
+0

이 일치 닫기 중괄호가'// 곱셈 (B)'의견 위로 가야한다. –

0

전환 후 case 문을 중괄호로 깜박입니다.

2

당신은 당신의 스위치 중괄호가 필요합니다 추측에서

switch (...) 
{ // your forgot this 
    ... 
} // and this