add compare.
This commit is contained in:
parent
4a21a93e6c
commit
31a6753312
12
src/main.rs
12
src/main.rs
@ -1,3 +1,4 @@
|
||||
use std::cmp::Ordering;
|
||||
use std::io;
|
||||
use rand::Rng;
|
||||
|
||||
@ -13,5 +14,14 @@ fn main() {
|
||||
io::stdin().read_line(&mut guess_number)
|
||||
.expect("Failed to read line.");
|
||||
|
||||
println!("You guess : {:?}", guess_number)
|
||||
let guess_number: u32 = guess_number.trim().parse()
|
||||
.expect("Not a number.");
|
||||
|
||||
println!("You guess : {:?}", guess_number);
|
||||
|
||||
match guess_number.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