Help with if/else statements

Hey, I'm just getting started with learning c++ and put together a quick practice program to get myself used to input/output and if/else. I'm having an issue with the if/else statement where even when the conditions are met, the program is registering as false and continuing onto else. I've tried looking up the issue and haven't found an answer, and can only guess at this point that is has something to do with the yorn variable being a string.

Does anyone know how to fix this problem?

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>
using namespace std;
int main(){
	char name[100], yorn[5];
	cout << "What is your name?" << endl;
	cin.getline (name, 100);
	cout << "Hello, " << name << "!" <<endl;
	int age;
	cout << "How old are you?" << endl;
	cin >> age;
	cout << "Have you had a birthday yet this year?" << endl;
	cin.ignore();
	cin.getline (yorn, 5);
	if (yorn == "yes" || yorn == "Yes"){ //for some reason, always registers false and continues to else
		cout << "You were born in the year " << 2019-age << "." << endl;
		system ("PAUSE");
		return 0;
	}
	else{ 
		cout << "You were born in the year " << (2019-age)-1 << "." << endl;
		system ("PAUSE");
		return 0;
	}
return 0;
}
If you run it in www.cpp.sh line 14 gest a yellow triangle mark. Hover the mouse cursor over it and see an info pop up.
Thanks, was able to figure it out because of that. I've gotten used to python and had been under the assumption that char and string were the same thing, so I'd been saving yorn as a char. Changing it to a string solved the issue!
Topic archived. No new replies allowed.