Comparing strings inside an if else statement

I'm trying to figure out how to compare strings inside an if else statement. Well my string is named country and right after I ask the user to input the name of their country, I want to use an if else statement to see of they qualify for an event.

If ((age>18) && (country==Serbia) || (country==Peru))
cout <<"You do not qualify for the event";
Else
If ((age>18)
cout <<"You qualify for the event";

Everytime I want to test for Serbia and Peru, the first if statement gets skipped and automatically goes to the second one and produces the cout.
How do I fix this? I want it to go through the first if statement so it can check the condition.
Last edited on
probably better to use string::compare to do so

if Serbia is a string, ok, but if you mean "Serbia", you need to add double-quotes.
1
2
if( age < 19 || country == Serbia || country == Peru ) std::cout << "no\n" ;
else std::cout << "yes\n" ; // age is greater than 18 and country is not either Serbia or Peru 

http://coliru.stacked-crooked.com/a/75f6653efe21f2d6
Topic archived. No new replies allowed.