This commit is contained in:
Tyrel Souza 2023-02-25 00:44:38 -05:00
parent 53a2181a80
commit 76e0c04081
No known key found for this signature in database
GPG Key ID: F3614B02ACBE438E

View File

@ -1,21 +1,33 @@
use std::io;
use rand::Rng;
use std::cmp::Ordering;
use std::io;
fn main() {
println!("Guess the number!");
let secret_number = rand::thread_rng().gen_range(1..=100);
println!("psst. the secret number is {secret_number}");
loop {
println!("Please input your guess.");
let mut guess = String::new();
io::stdin()
.read_line(&mut guess)
.expect("Failed to read line");
println!("Please input your guess.");
let guess: u32 = match guess.trim().parse() {
Ok(num) => num,
Err(_) => continue,
};
let mut guess = String::new();
io::stdin()
.read_line(&mut guess)
.expect("Failed to read line");
println!("You guessed {guess}");
println!("You guessed {guess}");
}
match guess.cmp(&secret_number) {
Ordering::Less => println!("Too Small"),
Ordering::Greater => println!("too big"),
Ordering::Equal => {
println!("you win");
break;
}
}
}
}