How can I get the user to input text instead of numbers in this program. haw can i get the cin statement to accept text? Do i have to use 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;
}
---EDIT--- Why won't this work?
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;
}
Thank you everybody! If you're interested, you can check out the game I made here. http://pastebin.com/pmCEJU8E You are helping a young programmer accomplish his dreams.