Reputation: 145
I am currently trying to understand why this problem is occurring with my code and I am not sure how to fix this..
int main()
{
char answer;
std::cin >> answer; // valid input is a, b, c or d
while(answer > 'd') // doesn't enter no matter what letter I input
{
retry(); // function call to print something long..
std::cin >> answer;
}
//rest of code not shown since everything is fine after this problem;
}
My goal of this program is to have the user input letters a, b, c, or d and after that it will trigger a "switch' function. So I figured that I can just have a while loop that keeps asking the user to enter a valid letter if they entered one not allowed. However, it doesn't seem to work?
Problem: I want while loop to activate when a letter greater than 'd' is entered, but the loop never happens no matter what letter I input.
Upvotes: 0
Views: 1369
Reputation:
Some common mistakes regarding stream IO are:
Your fail regarding 2 and 3.
Upvotes: 1