Skip to content

Instantly share code, notes, and snippets.

@barraponto
Created December 2, 2018 22:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barraponto/c88a2a1602e786ef948dc674d16905e1 to your computer and use it in GitHub Desktop.
Save barraponto/c88a2a1602e786ef948dc674d16905e1 to your computer and use it in GitHub Desktop.
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