2010-04-15 203 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

在猜測,匹配的右括號應該去'//乘法(二)'註釋以上。 – 2010-05-09 05:11:25

0

您在切換後忘記了case語句周圍的大括號。

2

您需要括號爲交換機:

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