Created
December 2, 2018 22:30
-
-
Save barraponto/c88a2a1602e786ef948dc674d16905e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::io; | |
fn get_guess() -> i32 { | |
let mut guess = String::new(); | |
io::stdin() | |
.read_line(&mut guess) | |
.expect("Failure reading input."); | |
match guess.trim().parse::<i32>() { | |
Ok(number) => number, | |
Err(_) => { | |
println!("Please enter a valid number."); | |
return get_guess(); | |
} | |
} | |
} | |
fn main() { | |
println!("Try guessing the secret number:"); | |
let guess = get_guess(); | |
println!("You guessed {}", guess); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment