-1

1 2 3 と 4 のどちらを入力したかに応じて、減算、加算、除算、または乗算を行う単純な計算機をプログラミングしています。このエラーが発生し続けます。私はC++の初心者であることを覚えておいてください。Mode == 3 および Mode == 4 の IF 行で発生します。

#include <iostream>

int main(){
using namespace std;
int x;
int y;
int x2;
int y2;
int x3;
int y3;
int x4;
int y4;
int Mode;

cout << "Welcome to Brian's Calculator!";
cout << endl;
cout << "Pick a mode. 1 is Addition. 2 Is Subtraction. 3 is Multiplacation. 4 is          Division";
cin >> Mode;

if (Mode==1){
cout << "You chose addition.";
    cout << endl;
 cout << "Pick a number.";
cout << endl;
cin >> x;
cout << endl;
cout << "Pick another.";
cout << endl;
cin >> y;
cout << "The sum of the numbers you chose are: " << x+y <<".";
return 0;   
   };

 if (Mode==2){
    cout << "You chose subtraction.";
    cout << endl;
     cout << "Pick a number.";
cout << endl;
cin >> x2;
cout << endl;
cout << "Pick another.";
cout << endl;
cin >> y2;
cout << "The difference of the numbers you chose are: " << x2-y2 <<".";}
return 0;
};

if (Mode==3){
    cout << "You chose Multiplacation.";
    cout << endl;
     cout << "Pick a number.";
cout << endl;
cin >> x3;
cout << endl;
cout << "Pick another.";
cout << endl;
cin >> y3;
cout << "The product of the numbers you chose are: " << x3*y3 <<".";
 return 0;
};

 if (Mode==4){
    cout << "You chose Division.";
    cout << endl;
     cout << "Pick a number.";
cout << endl;
cin >> x4;
cout << endl;
cout << "Pick another.";
cout << endl;
cin >> y4;
cout << "The quotient of the numbers you chose are: " << x4/y4 <<".";
return 0;
};
4

3 に答える 3

0

この行で:

cout << "The difference of the numbers you chose are: " << x2-y2 <<".";}

あなたは余分を持っています}

于 2013-10-25T01:55:29.990 に答える
0

問題: エンド ブレースが 1 つではなく 2 つある場合:

if (Mode==2){
...
// DELETE THE EXTRANEOUS "}"!
cout << "The difference of the numbers you chose are: " << x2-y2 <<".";}
return 0;
};

推奨される代替手段:

if (Mode==2){
  ...
  // DELETE THE EXTRANEOUS "}"!
  cout << "The difference of the numbers you chose are: " << x2-y2 <<".";
  return 0;
}

さらに良い:

  switch (Mode) {
    case 1 :
      ...
      break;

    case 2 :
      ...
      break;
于 2013-10-25T01:55:40.943 に答える
0

この行には、間違った場所があります}

cout << "The difference of the numbers you chose are: " << x2-y2 <<".";}
                                                                       ^

}プログラムの終了後に追加で閉じる必要があることを修正するとmain、同様に閉じることができます。また、次のようにifステートメントを閉じるときに;必要はありません。}

if (Mode==1){
// code...
};
 ^
于 2013-10-25T01:57:05.903 に答える