このプログラムでユーザーに数字の代わりにテキストを入力させるにはどうすればよいですか? テキストを受け入れる cin ステートメントを取得するにはどうすればよいですか? char を使用する必要がありますか?
int main()
{
using namespace std;
int x = 5;
int y = 8;
int z;
cout << "X=" << x << endl;
cout << "Y=" << y << endl;
cout << "Do you want to add these numbers?" << endl;
int a;
cin >> a;
if (a == 1) {
z = add(x, y);
}
if (a == 0) {
cout << "Okay" << endl;
return 0;
}
cout << x << "+" << y << "=" << z << endl;
return 0;
}
---編集--- なぜこれが機能しないのですか?
int main()
{
using namespace std;
int x = 5;
int y = 8;
int z;
cout << "X = " << x << " Y = " << y << endl;
string text;
cout << "Do you want to add these numbers together?" << endl;
cin >> text;
switch (text) {
case yes:
z = add(x, y);
break;
case no: cout << "Okay" << endl;
default:cout << "Please enter yes or no in lower case letters" << endl;
break;
}
return 0;
}
みんなありがとう!興味のある方は、ここで私が作ったゲームをチェックしてみてください。 http://pastebin.com/pmCEJU8E あなたは若いプログラマーが夢を実現するのを手伝っています。