#include #include #include #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"; unsigned seed = chrono::system_clock::now().time_since_epoch().count(); default_random_engine engine {seed}; uniform_int_distribution distribution {1, 100}; auto r {bind(distribution, engine)}; const int correct {r()}; int guessing {0}; for (;;) { cout << "Go ahead: "; int guess {0}; cin >> guess; ++guessing; if (!cin) { cerr << "Sorry, that wasn't a number.\n"; return EXIT_FAILURE; } if (guess == correct) { break; } if (guess < correct) { cout << "Too low."; } else { cout << "Too high."; } cout << " Try again.\n\n"; } cout << "That's right, the number was " << correct << ".\n"; if (guessing == 1) { cout << "You took " << guessing << " try. Nice job, mind reader.\n"; } else { cout << "You took " << guessing << " tries. Good to know, you're not a wizard.\n"; } return EXIT_SUCCESS; }