Write a do/while loop to get a number in the range 1 through 4 from the user, with error checking. This means that if they type a bad number, it will loop again.
#include <iostream>
int main() {
int number;
do {
std::cout << "Enter number between 1 and 4\n";
std::cin >> number;
} while (number < 1 || number > 4);
std::cout << "You entered " << number;
return 0;
}
Comments
Leave a comment