我想有一個if語句是真或根據假以它被賦予的用戶輸入,但是當我把條件,它說這個無效的操作數的二進制表示 (「字符串」(又名這裏的basic_string的')和「廉政」)如果統計陳述沒有工作
是我的代碼
#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;
}
沒有幫助很多還在說同樣的事情 – user1610489
@ user1610489看看我的回答 –
@ user1610489是,將其更改爲'如果你,如果你想比較字符串不能使用== int'。但是,你的目的是使用整數。 –