From 790507ced6c58588696a6664a5410ed5c54de362 Mon Sep 17 00:00:00 2001 From: robin Date: Sun, 9 Jun 2024 21:02:55 +0200 Subject: [PATCH] src/main.rs aktualisiert Added code to detect if the input has an letter --- src/main.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index aec0197..ab6ff09 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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"); - } \ No newline at end of file + +} \ No newline at end of file