equals

the code doesn't recognize equals in if (ans.equals("good"))

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
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>
#include <string>

using namespace std;

int main()
{
	string ans;
	char name[50];
	cout << "hello what is your name\n" << endl;
	cin >> name;
	cout << "nice to meet your " << name << endl;
	cout << "how is your day " << name << endl;
	cin >> ans;
	if (ans.equals("good"))
	{
		cout << "thats good" << endl;
	}
	else
	{
		cout << "thats bad" << endl;
	}
	return 0;
}
//should run like...
//hello what is your name
//kyle
//nice to meet your kyle
//how was your day kyle
//good
//thats good

//or...
//hello what is your name
//kyle
//nice to meet your kyle
//how was your day kyle
//bad
//thats bad 
Last edited on
1
2
// if (ans.equals("good"))
if( ans == "good" )


And, make name a string too.
1
2
//char name[50];
string name ;
thanks
soooooooooooooo much ive been trying this for ever i quit for a while and now it works your awsome
Last edited on
Topic archived. No new replies allowed.