Skip to content

Instantly share code, notes, and snippets.

@ngsw-taro
Created October 28, 2014 11:42
Show Gist options
  • Save ngsw-taro/0a310a3628fadc2df2d4 to your computer and use it in GitHub Desktop.
Save ngsw-taro/0a310a3628fadc2df2d4 to your computer and use it in GitHub Desktop.
Rust超入門勉強会でつくったやつ #learnrust_jp
// TODO かっこよくする
use std::io;
use std::rand;
const MAX: uint = 100;
fn main() {
println!("数当てゲーム");
println!("範囲: 0~{}", MAX);
let my_num = (rand::random::<uint>() % MAX) as int;
let mut count: int = 0;
loop {
print!("> ")
let result = io::stdin().read_line();
match result {
Ok(value) => {
let your_num_option = from_str::<int>(value.as_slice().trim());
match your_num_option {
Some(your_num) => {
count += 1;
if my_num < your_num {
println!("もっと小さい数です");
} else if my_num > your_num {
println!("もっと大きい数です");
} else {
println!("大正解🍺");
println!("回答数: {}", count);
break;
}
}
None => {
println!("数を入力してください");
}
}
}
Err(e) => {
println!("error: {}", e);
break;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment