-
Modifying a while loop
How can this loop be modified so that the statement "Please select an item from the list." is only repeated 3 times, and after the third unsecessful try a new message is displayed, ex. " You can't follow instructions, Good Bye"
Code:
while ((item != 1) && (item != 2) && (item != 3) && (item != 4))
{
cout << "Please select an item from the list." << endl ;
cin >> item;
}
-
Add a counter called numGuesses, which gets incremented each time.
Code:
while ( numGuesses < 3 && (item != 1) && (item != 2) && (item != 3) && (item != 4))
{
cout << "Please select an item from the list." << endl ;
cin >> item;
numGuesses++;
}
Use the value to alter your prompt