forked from inancgumus/learnrust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_naked.rs
40 lines (35 loc) · 961 Bytes
/
_naked.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use rand::Rng;
use std::cmp::Ordering::*;
use std::io;
use std::io::Write;
fn main() {
let secret = rand::thread_rng()
.gen_range(1, 101);
loop {
print!("guess: ");
io::stdout()
.flush()
.expect("🤬 cannot flush");
let mut guess = String::new();
io::stdin()
.read_line(&mut guess)
.expect("🤬 cannot read input");
let guess: u32 = match guess.trim().parse() {
Ok(n) => n,
Err(_) => {
println!("🤬 not a number");
continue;
}
};
println!("you say: {}, let's see...", guess);
match guess.cmp(&secret) {
Less => println!("🤨 bigger"),
Greater => println!("🤨 smaller"),
Equal => {
println!("🥳 you rock!");
break; // exit the loop
}
}
println!();
}
}