Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner 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
You can’t perform that action at this time.