Guessing stuff with a shadowed var
This commit is contained in:
parent
0f51230e76
commit
71b5816a4d
@ -1,5 +1,6 @@
|
||||
extern crate rand;
|
||||
|
||||
use std::cmp::Ordering;
|
||||
use std::io;
|
||||
use rand::Rng;
|
||||
|
||||
@ -17,5 +18,14 @@ fn main() {
|
||||
io::stdin().read_line(&mut guess)
|
||||
.expect("Failed to read line");
|
||||
|
||||
let guess: u32 = guess.trim().parse()
|
||||
.expect("Please type a number!");
|
||||
|
||||
println!("You guessed: {}", guess);
|
||||
|
||||
match guess.cmp(&secret_number) {
|
||||
Ordering::Less => println!("Too small!"),
|
||||
Ordering::Greater => println!("Too big!"),
|
||||
Ordering::Equal => println!("You win!"),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user