• ### Popular Now

• 15
• 15
• 11
• 9
• 10

#### Archived

This topic is now archived and is closed to further replies.

# If/Else Condition with Characters

This topic is 5117 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

What I have has no errors, but does a infinite loop. I want it to recognize the "y" the character inputs in a do/while loop in c++.
char abilityAnswer[2];
do {
system("cls");
cout << "Ability Modifiers:" << endl;
cout << "------------------\n" << endl;
cout << "\tStrength: " << Player.STR << "          Intelligence: " << Player.INT << endl;
cout << "\tDexterity: " << Player.DEX << "     Wisdom: " << Player.WIS << endl;
cout << "\tConstitution: " << Player.CON << "   Charisma: " << Player.CHA << endl;

cout << "Type ''y'' or ''n'' to continue: ";


##### Share on other sites
The != operator is not defined for character arrays. Use a std::string, test against a single character (abilityAnswer[0] != ''y'' - note the single quotation), or use strcmp/

##### Share on other sites
I''m extremely new to std::string. Does it need the #include <string> header? And can you fix my code above so I can see it visually? Thanks.