dust/examples/guessing_game.ds

27 lines
547 B
Plaintext
Raw Normal View History

# 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.")
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
}