Skip to content

devaniketh/cargo-guess

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Guessing Game in Rust

Rust License Status


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.


Game Overview

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.


Features

  • Random number generation using the rand crate
  • Handles multiple guesses in a loop
  • Validates user input (ignores invalid entries without crashing)
  • Provides real-time feedback on guesses

Installation

  1. Ensure you have Rust and Cargo installed.
  2. Clone the repository:
    git clone <your-repo-url>
    cd guessing_game
  3. Build the project:
    cargo build

Usage

Run the game using:

  cargo run

example

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!

How It Works

1.The program generates a secret number between 1 and 100 using the rand crate.

2.It prompts the player to input a guess.

3.The guess is parsed as a number and compared with the secret number using Rust’s match statement.

4.Feedback is provided:

  • Too small!

  • Too big!

  • You win! (ends the loop)

5.Invalid inputs are ignored, and the player can guess again.

Technologies Used

  • Rust
  • Cargo
  • Rand crate for random number generation
  • Standard library features: io, cmp::Ordering, loop, match, and shadowing

License

This project is open-source under the MIT License.

About

Guessing cli game on rust

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages