src/main.rs aktualisiert
Now the code does not crash if input is empty
This commit is contained in:
parent
aa3f9dbeb9
commit
2a7cc8269e
|
@ -7,12 +7,15 @@ fn main(){
|
|||
println!("Durch welche gehst du? Gib eine Zahl zwischen 1 und 3 ein");
|
||||
let secretnumber = rand::thread_rng().gen_range(1..=3);
|
||||
let mut guess = String::new();
|
||||
if guess == "" {
|
||||
let guess = secretnumber.to_string();
|
||||
}
|
||||
|
||||
io::stdin()
|
||||
.read_line(&mut guess)
|
||||
.expect("Failed to read line");
|
||||
if guess.trim().is_empty() {
|
||||
println!("Du kannst nicht cheaten");
|
||||
std::process::exit(0);
|
||||
|
||||
}
|
||||
let guess: u32 = guess.trim().parse().expect("Please type a number!");
|
||||
if guess == secretnumber {
|
||||
println!("Dein score: {}", score);
|
||||
|
|
Loading…
Reference in a new issue