Answer to Question #166946 in C++ for Novyet

Question #166946

   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.



1
Expert's answer
2021-02-25T17:14:53-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment