I'm currently working on a small project to learn (and for fun) and need a while-loop to check if a user's input is one of the integers 1, 2, 3, 4, or 5. What is the best way to do this? Here's my basic idea in code, but it's not quite working:
std::cin >> input;
while (cin.fail() == true || input != 1 && input != 2 && input != 3 && input != 4 && input != 5){
std::cout << std::endl "The valid choices are 1, 2, 3, 4, and 5. Please choose: ";
std::cin >> input;
std::cout << std::endl;
}
This only works if it's a digit above 5, but fails if I enter a letter. How can I use cin.fail() to validate correctly?