1
0
dust/examples/guessing_game.ds

29 lines
551 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.")
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;
}
}
}