num, Err(_) => continue, }; count += 1; println!("#{}: You guessed: {}", count, guess); match guess.cmp(&secret_number) { Ordering::Less => println!("Too small"), Ordering::Greater => println!("Too big"), Ordering::Equal => { println!("You win!!!!"); println!("Your hit count is {}", count); break; } } } }"> num, Err(_) => continue, }; count += 1; println!("#{}: You guessed: {}", count, guess); match guess.cmp(&secret_number) { Ordering::Less => println!("Too small"), Ordering::Greater => println!("Too big"), Ordering::Equal => { println!("You win!!!!"); println!("Your hit count is {}", count); break; } } } }"> num, Err(_) => continue, }; count += 1; println!("#{}: You guessed: {}", count, guess); match guess.cmp(&secret_number) { Ordering::Less => println!("Too small"), Ordering::Greater => println!("Too big"), Ordering::Equal => { println!("You win!!!!"); println!("Your hit count is {}", count); break; } } } }">
extern crate rand;
use std::io;
use std::cmp::Ordering;
use rand::Rng;
fn main() {
println!("Guess the number!");
let secret_number = rand::thread_rng().gen_range(1, 101);
let mut count = 0;
loop {
println!("Please input your guess.");
let mut guess = String::new();
io::stdin().read_line(&mut guess)
.expect("Failed to read line");
let guess: u32 = match guess.trim().parse() {
Ok(num) => num,
Err(_) => continue,
};
count += 1;
println!("#{}: You guessed: {}", count, guess);
match guess.cmp(&secret_number) {
Ordering::Less => println!("Too small"),
Ordering::Greater => println!("Too big"),
Ordering::Equal => {
println!("You win!!!!");
println!("Your hit count is {}", count);
break;
}
}
}
}
=
이 '복사'가 아니라 이동이라는 것을 확실히 이해해야 함