Aug 4, 2013 at 7:12pm UTC
So I am trying to make a console game to help me learn C++, but I have hit a snag... I need to use words in an if statement instead of what I have been doing before witch is 1 = yes and 0 = no, I would like it to be Yes = yes and No = no.
What I am doing to try this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#include <iostream>
#include <cstdlib>
using namespace std;
char input[80];
int main() {
system("clear" );
cout << "Start?" << endl;
cout << "> " ;
cin >> input;
if (input == "yes" ) {
cout << "User said 'yes'" << endl;
}
if (input == "no" ) {
cout << "User said 'no'" << endl;
}
if (input != "yes" || "no" ) {
cout << "User said nothing." << endl;
}
return 0;
}
But this doesn't work... Has any one got any ideas why?
Thanks.
Last edited on Aug 4, 2013 at 8:07pm UTC
Aug 4, 2013 at 7:21pm UTC
Could you tell me what strcmp is?
Last edited on Aug 4, 2013 at 8:07pm UTC
Aug 4, 2013 at 7:25pm UTC
This function compares character strings.
Aug 4, 2013 at 7:26pm UTC
Ok thanks man.
Last edited on Aug 4, 2013 at 8:07pm UTC