728x90
๋ฐ์ํ
์ ์ด๊ฑฐ ๊ฐ๋ ใ .ใ ๋ญ์๋ฆฌ ํ๋์ง ์ดํดํ๊ธฐ ์ค์ผ ํ๋ค์ง;;;
์ฌ๊ธฐ ๋ฐ๋ผํ๋ ์ค -> https://rinthel.github.io/rust-lang-book-ko/ch02-00-guessing-game-tutorial.html
์ด ์ธ์ด์ ๋ชจ๋ ํน์ง์ ๋ค ์ค๋ช ํด์ฃผ๋ ค๊ณ ํ๋ ๋๋์ด๋ผ์ ๋๊ฐ ํญ๋ฐํ๋ ๊ฒ ๊ฐ๋ค.
๋ด๊ฐ ์ด๋ ๊ฒ ๋ฐฅ๋ณด์๊ตฌ๋. ใ .ใ ;
๊ทผ๋ฐ ๋์๊ฐ ๋์ ์ ํ์ฑํฐ๋ง ๋๋ ์ธ๋ฉ๊ณ ์์ด๋ณด๋๊น ์ฌ์ ๋ ์๊ฒ ๊ฐ๊ธดํ๋ค.
๊ทธ๋ฅ ๋ค์ C/C++ ๊ณต๋ถํ ๊น...?
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);
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,
};
println!("You guessed: {}", guess);
match guess.cmp(&secret_number) {
Ordering::Less => println!("Too small!"),
Ordering::Greater => println!("Too big!"),
Ordering::Equal => {
println!("You win!");
break;
}
}
}
}
728x90
๋ฐ์ํ