If statements with words.

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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <cstring>


...

	if ( strcmp( input, "yes" ) == 0 ) {
		cout << "User said 'yes'" << endl;
	}
	if ( stdcmp( input, "no" ) == 0 ) {
		cout << "User said 'no'" << endl;
	}
	if ( strcmp( input, "yes" ) != 0  && strcmp( input, "no" ) != 0 ) {
		cout << "User said nothing." << endl;
	}
Could you tell me what strcmp is?
Last edited on
This function compares character strings.
Ok thanks man.
Last edited on
Topic archived. No new replies allowed.