A user has to select a choice from the menu, and the program's goal is to check whether the user has selected a valid choice or not. In python I would run a while loop and compare them using "in": (userChoice in validChoices). How do I do that in C++ using a while loop?
Valid choices are stored in this variable:
const char validChoices[12] = {'P', 'p', 'A', 'a', 'M', 'm', 'S', 's', 'L', 'l', 'Q', 'q'}
The program asks the user for input and stores it in a char variable:
char userChoice {};
std::cin >> userChoice;
If the choice is invalid, the program should say "Unknown selection, please try again" and ask again for the input until the user selects a valid option.
Appreciate the help in advance!! Been struggling with it a lot.
Current attempt:
bool isValidChoice = true;
while (isValidChoice)
{
char userChoice {};
std::cout << "Select a choice: ";
std::cin >> userChoice;
if ()
{
std::cout << "You have selected: " << userChoice << std::endl;
isValidChoice = false;
}
else
{
std::cout << "Unknown selection, please try again" << std::endl;
}