Handle parsing errors

This commit is contained in:
Manuel Thalmann 2024-10-12 00:29:01 +02:00
parent f7cbc03210
commit 21a351914f

View file

@ -16,7 +16,14 @@ fn main() {
.read_line(&mut guess)
.expect("Failed to read line");
let guess: u32 = guess.trim().parse().expect("Please type a number!");
let guess: u32 = match guess.trim().parse() {
Ok(num) => num,
Err(_) => {
println!("Please type a number!");
continue;
},
};
println!("You guessed: {guess}");
match guess.cmp(&secret_number) {