So I’m making a look that asks if you would like to level up your character. If you say yes it asks you again until you’re level 20 (the D&D level cap) or until you say no.
I type y then hit enter, it says it’s wrong, hit n then enter, same thing. Here’s my code:
char yn;
do {
cin >> yn;
while (yn != 'y' || yn != 'n') {
cout << "Only y or n are valid options, try again: ";
cin >> yn;
}
if (yn == 'y')
f.levelUp();
cout << endl;
} while(yn != 'n' || f.getLevel() != 20);
I feel like I’m missing something very obvious!
should be
Since it’s only invalid if the input is NOT
'y'AND it’s NOT'n'.Same goes for the outer loop when you’re checking for not
'n'AND not yet level 20, otherwise you can only exit that loop if you enter'n'and you’re at level 20.