Created
December 2, 2015 09:14
-
-
Save itkovian/e2023b86522d065679e3 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
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; | |
} | |
} | |
} | |
} |
Author
itkovian
commented
Dec 2, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment