add compare.

This commit is contained in:
licsber 2024-08-21 17:03:19 +08:00
parent 4a21a93e6c
commit 31a6753312

View File

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