diff --git a/guessing_game/src/main.rs b/guessing_game/src/main.rs index dc541c8..f412373 100644 --- a/guessing_game/src/main.rs +++ b/guessing_game/src/main.rs @@ -1,5 +1,6 @@ -use std::io; use rand::Rng; +use std::cmp::Ordering; +use std::io; fn main() { println!("Guess the number!"); @@ -13,5 +14,12 @@ fn main() { .read_line(&mut guess) .expect("Failed to read line"); + let guess: u32 = guess.trim().parse().expect("Please type a number!"); println!("You guessed: {guess}"); + + match guess.cmp(&secret_number) { + Ordering::Less => println!("Too small!"), + Ordering::Greater => println!("Too big!"), + Ordering::Equal => println!("You win!"), + } }