A simple command-line guessing game implemented in Rust. This project is a hands-on way to practice Rust fundamentals like variables, loops, functions, enums, error handling, and using external crates.
The program generates a random number between 1 and 100, and the player has to guess it.
After each guess, the program will indicate whether the guess is:
- Too low
- Too high
- Correct (the game ends)
The game continues until the player correctly guesses the number.
- Random number generation using the
randcrate - Handles multiple guesses in a loop
- Validates user input (ignores invalid entries without crashing)
- Provides real-time feedback on guesses
- Ensure you have Rust and Cargo installed.
- Clone the repository:
git clone <your-repo-url> cd guessing_game
- Build the project:
cargo build
Run the game using:
cargo runexample
Guess the number!
Please input your guess.
50
You guessed: 50
Too low!
Please input your guess.
75
You guessed: 75
Too high!
Please input your guess.
63
You guessed: 63
You win!
-
Too small!
-
Too big!
-
You win! (ends the loop)
- Rust
- Cargo
- Rand crate for random number generation
- Standard library features:
io,cmp::Ordering,loop,match, andshadowing
This project is open-source under the MIT License.