Parse and process the user input
This commit is contained in:
parent
04f7b04929
commit
5e325d386a
1 changed files with 9 additions and 1 deletions
|
@ -1,5 +1,6 @@
|
||||||
use std::io;
|
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
|
use std::cmp::Ordering;
|
||||||
|
use std::io;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("Guess the number!");
|
println!("Guess the number!");
|
||||||
|
@ -13,5 +14,12 @@ fn main() {
|
||||||
.read_line(&mut guess)
|
.read_line(&mut guess)
|
||||||
.expect("Failed to read line");
|
.expect("Failed to read line");
|
||||||
|
|
||||||
|
let guess: u32 = guess.trim().parse().expect("Please type a number!");
|
||||||
println!("You guessed: {guess}");
|
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 a new issue