2024-02-19 19:49:12 +00:00
|
|
|
# This is a Dust version of an example from the Rust Book.
|
|
|
|
#
|
|
|
|
# https://doc.rust-lang.org/book/ch02-00-guessing-game-tutorial.html
|
|
|
|
|
|
|
|
output("Guess the number.")
|
|
|
|
|
|
|
|
secret_number = int:random_range(0..=100);
|
|
|
|
|
|
|
|
loop {
|
|
|
|
output("Please input your guess.")
|
|
|
|
|
2024-02-19 20:24:44 +00:00
|
|
|
input = io:stdin():expect("Failed to read line.")
|
2024-02-19 19:49:12 +00:00
|
|
|
guess = int:parse(input);
|
|
|
|
|
|
|
|
output("You guessed: " + guess)
|
|
|
|
|
|
|
|
match cmp(guess, secret_number) {
|
|
|
|
Ordering::Less -> output("Too small!"),
|
|
|
|
Ordering::Greater -> output("Too big!"),
|
|
|
|
Ordering::Equal -> {
|
|
|
|
output("You win!");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2024-02-19 20:24:44 +00:00
|
|
|
}
|
2024-02-19 19:49:12 +00:00
|
|
|
|