guess1 [Rust] Guess 예제 (20일차) fn main() { let secret_number = 5; let mut guess = String::new(); println!("Please enter your guess:"); std::io::stdin().read_line(&mut guess) .expect("Failed to read line"); let guess: u32 = match guess.trim().parse() { Ok(num) => num, Err(_) => { println!("Please enter a number!"); return; }, }; if guess == secret_number { println!("You guessed it!"); } else { println!("Sorry, try again."); } .. 2023. 1. 1. 이전 1 다음