loop structure.
This commit is contained in:
parent
31a6753312
commit
35796d912b
27
src/main.rs
27
src/main.rs
@ -7,21 +7,26 @@ fn main() {
|
||||
|
||||
println!("Secret number is {:?}", secret_number);
|
||||
|
||||
println!("Guessing a number:");
|
||||
loop {
|
||||
println!("Guessing a number:");
|
||||
|
||||
let mut guess_number = String::new();
|
||||
let mut guess_number = String::new();
|
||||
|
||||
io::stdin().read_line(&mut guess_number)
|
||||
.expect("Failed to read line.");
|
||||
io::stdin().read_line(&mut guess_number)
|
||||
.expect("Failed to read line.");
|
||||
|
||||
let guess_number: u32 = guess_number.trim().parse()
|
||||
.expect("Not a number.");
|
||||
let guess_number: u32 = guess_number.trim().parse()
|
||||
.expect("Not a number.");
|
||||
|
||||
println!("You guess : {:?}", guess_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!")
|
||||
match guess_number.cmp(&secret_number) {
|
||||
Ordering::Less => println!("Too small."),
|
||||
Ordering::Greater => println!("Too big."),
|
||||
Ordering::Equal => {
|
||||
println!("You win!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user