Anonymous user
Guess the number/With feedback (player): Difference between revisions
Guess the number/With feedback (player) (view source)
Revision as of 00:55, 22 September 2014
, 9 years ago→{{header|Rust}}
Line 1,974:
=={{header|Rust}}==
{{works with|rustc|0.
<lang rust>use std::io::stdio::stdin;
use std::ascii::AsciiExt;
static
static
fn main() {
let mut
loop {▼
let mut
let mut max = MAX;
let mut num_guesses = 1i;
println!("Please think of a number between {} and {}", min, max);
let guess = (min + max) / 2;
▲ loop {
println!("Is it {}?", guess);
println!("
match stdin.read_line().ok().and_then(|line| line.as_slice().trim().to_ascii_upper().shift_char()) {
max = guess - 1;
}
Some('L') => {
min = guess + 1;
if num_guesses == 1 {
▲ }
println!("\n*** That was easy! Got it in one guess! ***\n");
} else {
println!("\n*** I knew it! Got it in only {} guesses! ***\n", num_guesses);
▲ "q" | "Q" => break,
break;
},
Some('Q') => return,
_ => println!("Sorry, I didn't quite get that. Please try again.")
}
▲ break;
}
}</lang>
|