与えられたユーザー入力に応じて if ステートメントを true または false にしようとしていますが、条件を入れると、この無効なオペランドがバイナリ式 ('string'(aka 'basic_string') および 'int') に指定されます。
ここに私のコードがあります
#include <iostream>
#include <string>
using namespace std;
int main()
{
cout << " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" << endl;
cout << " X X" << endl;
cout << " X MENU X" << endl;
cout << " X X" << endl;
cout << " X Press 1 to Play The Word Game. X" << endl;
cout << " X X" << endl;
cout << " X Press 2 Too See a calculator. X" << endl;
cout << " X X" << endl;
cout << " X X" << endl;
cout << " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" << endl
<< endl;
string userinput;
cin >> userinput;
if (userinput == 1);{
while (1<2)
{
cout << "Enter the Word." << endl;
string UserInput;
cin >> UserInput;
cout << endl << UserInput << " is is not the right word but keep on trying" << endl << endl;
cout << "Press Enter to Continue.";
cin.clear();
cin.ignore(255, '\n');
cin.get();
return 0;
}
}
if (userinput == 2);
{ int z;
int x;
int sum;
cout << " welcome to the calculator" << endl << endl;
cin.clear();
cin.ignore(255, '\n');
cin.get();
cout << "enter your first number";
cin >> z; cout << endl << endl;
cout << "enter your second number" << endl;
cin >> x; cout << endl << endl;
sum = z + x;
cout << sum;
}
cin.clear();
cin.ignore(255, '\n');
cin.get();
return 0;
}