Handle parsing errors
This commit is contained in:
parent
f7cbc03210
commit
21a351914f
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue