#include #include using namespace std; int main() { cout << "I am thinking of a number in the range 1 to 100 inclusive.\n" << "Keep trying until you guess it.\n\n"; int correct {56}; for (;;) { //Looks like an infinite loop, but it isn't. cout << "Go ahead: "; int guess {0}; cin >> guess; if (!cin) { cerr << "Sorry, that wasn't a number.\n"; return EXIT_FAILURE; } if (guess == correct) { break; //out of the for loop } //Give the user a hint. if (guess < correct) { cout << "Too low."; } else { cout << "Too high."; } cout << " Try again.\n\n"; } //Arrive here after the break. cout << "That's right, the number was " << correct << ".\n"; return EXIT_SUCCESS; }