From 5e325d386a8f3daa3845fe4c267a1df3c8c3737d Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Sat, 12 Oct 2024 00:17:30 +0200 Subject: [PATCH] Parse and process the user input --- guessing_game/src/main.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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!"), + } }