src/main.rs aktualisiert

Added code to detect if the input has an letter
This commit is contained in:
robin 2024-06-09 21:02:55 +02:00
parent 0a8c1d9a98
commit 790507ced6

View file

@ -11,8 +11,13 @@ fn main(){
io::stdin()
.read_line(&mut guess)
.expect("Failed to read line");
if guess.trim().is_empty() {
println!("Die opiton ist unknown");
if guess.chars().any(|c| c.is_alphabetic()) {
println!("Deine Eingabe enthält einen Buchstaben");
}
else {
if guess.trim().is_empty() {
println!("Die opiton ist unbekannt");
}
else {
@ -23,14 +28,13 @@ fn main(){
std::process::exit(0);
}
if guess > 4 {
println!("die option ist unbekannt")
println!("die option ist unbekannt");
}
else {
println!("Du hast überlebt");
let _score = score += 1;
println!("Der Geist ist hinter der Tür {}", secretnumber);
}
}
}
}}}}
println!("Du hast gewonnen");
}
}