ok how can i get it so it will ask for a string and the string will be and number of char long.
ex:
hello or hi
and have if check the string to do something like this:
ok you tyeped hello so the program will say "hello to you too"
Printable View
ok how can i get it so it will ask for a string and the string will be and number of char long.
ex:
hello or hi
and have if check the string to do something like this:
ok you tyeped hello so the program will say "hello to you too"
If you're familiar with the C++ string class, just use cin >> yourString like you would with an int.
Code:
string user_input;
cout << "Enter a statement: ";
cin >> user_input;
if ("hello" == user_input) //overloaded <string> class == boolean operator simulates the <cstring> strcmp( ) function
{
do stuff here
}
else if ("hi" == user_input)
{
do stuff here
}
else
{
do stuff here
}
[edit] moved constants to the left-hand side of the == based on this tip [/edit]
thanx that was easyer than i thought