sheesh; this is harder than it should be

This commit is contained in:
2024-12-23 01:37:10 -06:00
commit fbe19464eb
4 changed files with 175 additions and 0 deletions

27
src/main.rs Normal file
View File

@ -0,0 +1,27 @@
use std::io;
use rand::Rng;
use std::cmp::Ordering;
fn main() {
println!("Let's play the guessing game!");
let secret_number = rand::thread_rng().gen_range(1..=100);
loop {
println!(" What's your guess?");
let mut guess = String::new();
io::stdin()
.read_line(&mut guess)
.expect("Sorry; something didn't quite work.");
let guess: u32 = match guess.trim().parse() {
Ok(num) => num,
Err(_) => continue,
};
match guess.cmp(&secret_number) {
Ordering::Less => println!("...bigger!"),
Ordering::Greater => println!("...smaller!"),
Ordering::Equal => {
println!("You got it - it's {}!", secret_number);
break;
}
}
}
}