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: ";
cin.getline(abilityAnswer, 2, ''\n'');
} while (abilityAnswer != "y");
If/Else Condition with Characters
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++.
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/
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement