mirror of
https://github.com/Noratrieb/simple-std.git
synced 2026-01-16 09:25:05 +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);
|
let number = random_int_range(0..100);
|
||||||
loop {
|
loop {
|
||||||
let input = prompt("Guess: ").parse::<i32>().expect("not a number");
|
let input = prompt("Guess: ").parse::<i32>().expect("not a number");
|
||||||
if input < number {
|
match input.cmp(&number) {
|
||||||
println!("Higher");
|
Ordering::Less => println!("Too Small"),
|
||||||
} else if input > number {
|
Ordering::Greater => println("Too Big"),
|
||||||
println!("Lower");
|
Ordering::Equal => {
|
||||||
} else {
|
println("You win!");
|
||||||
println!("Correct!");
|
break;
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue