Skip to content

Instantly share code, notes, and snippets.

@itkovian
Created December 2, 2015 09:14
Show Gist options
  • Save itkovian/e2023b86522d065679e3 to your computer and use it in GitHub Desktop.
Save itkovian/e2023b86522d065679e3 to your computer and use it in GitHub Desktop.
extern crate rand;
use rand::Rng;
use std::cmp::Ordering;
use std::io;
fn main() {
let secret_number = rand::thread_rng().gen_range(1,101);
let mut guess = String::new();
loop {
println!("Give ussss a numbers? ");
io::stdin().read_line(&mut guess)
.ok()
.expect("Failed to read line");
let guess_: u32 = match guess.trim().parse() {
Ok(num) => num,
Err(_) => continue,
};
println!("You guessed: {}", guess_);
match guess_.cmp(&secret_number) {
Ordering::Less => println!("Too small"),
Ordering::Greater => println!("Too big"),
Ordering::Equal => {
println!("Got it!");
break;
}
}
}
}
@itkovian
Copy link
Author

itkovian commented Dec 2, 2015

            Err(_)  => {
                println!("Oops! cannot parse {}", guess);
                continue;
            },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment