Answer:
#include <iostream>
int main() {
int n;
while (true) {
std::cout << "Enter an integer in the range 0 < n < 100: ";
std::cin >> n;
if (n > 0 && n < 100) {
break;
}
std::cout << "Invalid input. Please try again." << std::endl;
}
std::cout << "Valid input: " << n << std::endl;
return 0;
}
Step-by-step explanation:
This program starts an infinite loop using the while (true) construct. Inside the loop, it prompts the user to enter an integer and reads the input using cin >> n.
It then checks if the value of n is in the range 0 < n < 100 using an if statement. If the value is in the range, the loop is exited using the break statement. If the value is not in the range, the program prints an error message and continues the loop.
This loop will continue until the user enters a valid integer in the specified range. When a valid integer is entered, the program will print a message indicating that the input is valid and the value of n. The program will then terminate.