Parse and process the user input

This commit is contained in:
Manuel Thalmann 2024-10-12 00:17:30 +02:00
parent 04f7b04929
commit 5e325d386a

View file

@ -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!"),
}
}