A simple Rust program where the player tries to guess a randomly generated number between 1 and 100.
- The program generates a random secret number between 1 and 100.
- The player has a maximum of
log2(100) + 1 = 7
attempts to guess the number. - After each guess, the program provides feedback:
- >> Too small!: The guess is lower than the secret number.
- >> Too big!: The guess is higher than the secret number.
- ## You WIN! ##: The guess matches the secret number, and the game ends.
- If the player fails to guess the number within the allowed attempts, the game ends with a "Sorry, you LOOSE :(" message.
git clone https://github.com/trendev/guessing_game.git
cd guessing_game
cargo run
Guess the number in 7 attempts!
7 - Please input your guess:
50
You guessed: 50
<< Too big!
6 - Please input your guess:
25
You guessed: 25
>> Too small!
5 - Please input your guess:
37
You guessed: 37
>> Too small!
4 - Please input your guess:
42
You guessed: 42
## You WIN! ##
Guess the number in 7 attempts!
7 - Please input your guess:
50
You guessed: 50
<< Too big!
6 - Please input your guess:
25
You guessed: 25
>> Too small!
5 - Please input your guess:
37
You guessed: 37
>> Too small!
4 - Please input your guess:
40
You guessed: 40
>> Too small!
3 - Please input your guess:
45
You guessed: 45
<< Too big!
2 - Please input your guess:
43
You guessed: 43
<< Too big!
1 - Please input your guess:
41
You guessed: 41
>> Too small!
## Sorry, you LOOSE :( ##
- Rust (version
1.67
or later)
Enjoy playing and improving your guessing skills (using binary search logic or dichotomy...)!