mirror of
https://github.com/Noratrieb/simple-std.git
synced 2026-01-14 16:35:06 +01:00
use Ordering instead of if else
This commit is contained in:
parent
52fbc279fb
commit
9a18b81523
1 changed files with 7 additions and 7 deletions
14
README.md
14
README.md
|
|
@ -39,13 +39,13 @@ fn main() {
|
|||
let number = random_int_range(0..100);
|
||||
loop {
|
||||
let input = prompt("Guess: ").parse::<i32>().expect("not a number");
|
||||
if input < number {
|
||||
println!("Higher");
|
||||
} else if input > number {
|
||||
println!("Lower");
|
||||
} else {
|
||||
println!("Correct!");
|
||||
break;
|
||||
match input.cmp(&number) {
|
||||
Ordering::Less => println!("Too Small"),
|
||||
Ordering::Greater => println("Too Big"),
|
||||
Ordering::Equal => {
|
||||
println("You win!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue