Number Guessing Game
Build a classic guess-the-number game from scratch in modern C++ with zero external dependencies. You generate a secret number with the <random> library, read player guesses from std::cin, and give higher or lower feedback inside a game loop until they win. A friendly first project that turns loops, conditionals, and input handling into something genuinely fun to play.
Support Free C++ Education
Help us keep this platform free for everyone! Your support enables us to create more high-quality lessons, exercises, and interactive content.
What You'll Build
A working console game that picks a random secret number, counts your attempts, tells you whether each guess is too high or too low, and lets you play again without restarting.
Learning Objectives
- Generate random numbers with std::mt19937 and std::uniform_int_distribution from <random>
- Read and validate integer input from std::cin, clearing the stream on bad input
- Control flow with while and do-while loops until a win condition is met
- Compare values with if and else if to drive higher or lower hints
- Track state such as attempt counts using plain int variables
- Structure the program into small functions with clear parameters and return types
Project Steps
Number Guessing Game
Write the whole game: draw a secret number, loop on the player's guesses with higher and lower hints, count the attempts, and offer another round.