2017-10-26 10 views
-2

このコードは大きなプログラムの一部です。私は間違っているかもしれませんが、実行時に画面上に図形名を表示しないでください半径と高さの後に?私は正方形のために2を入力しても、現在三角形と言っています。文字列値をC++の文字列変数に代入する

cout << "Please enter your choice of shape from the following menu: \n\n" 
     << "1. triangle\n" 
     << "2. square\n" 
    cin >> choice;  

if (choice = 1) 
    shape = "triangle" ; 
else if (choice = 2) 
    shape = "square"; 

cout << "Enter the side of the " << shape << ": ? "; 
cin >> side; 
+1

'='は代入演算子です。等号を調べるには '=='を使います。これをキャッチするには、コンパイラの警告をオンにします。 (たとえば、g ++を使用している場合、 '-Wall'を追加すると、誤って' = 'を使用したときに警告が表示されます。 – Ryan

+0

半径と高さ? – molbdnilo

答えて

1

choice==1それ以外の場合は、割り当てます。平等チェックを使用する必要があります。

if (choice == 1) 
    shape = "triangle" ; 
else if (choice == 2) 
    shape = "square"; 
関連する問題