Guessing stuff with a shadowed var

This commit is contained in:
Dan Buch 2017-12-21 22:49:29 -05:00
parent 0f51230e76
commit 71b5816a4d
Signed by: meatballhat
GPG Key ID: 9685130D8B763EA7

View File

@ -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!"),
}
}