Skip to content

Commit

Permalink
値の比較を行った refs #4
Browse files Browse the repository at this point in the history
  • Loading branch information
euledge committed Feb 10, 2019
1 parent e28d952 commit e0c3071
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Chapter2/gussing_game/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
extern crate rand;

use std::io;
use std::cmp::Ordering;
use rand::Rng;

fn main() {
Expand All @@ -17,5 +18,13 @@ fn main() {
.read_line(&mut guess)
.expect("failed to read line");

let guess:i32 = guess.trim().parse().expect("Please type a number!");

println!("You guessed: {}", guess);

match guess.cmp(&secret_number) {
Ordering::Less => println!("Too small!"),
Ordering::Greater => println!("Too Big!"),
Ordering::Equal => println!("You Win!")
}
}

0 comments on commit e0c3071

Please sign in to comment.