Created
October 28, 2019 08:33
-
-
Save SnowyPainter/3015a370a8834b3539442dfec7232ccc to your computer and use it in GitHub Desktop.
It's my first rust project.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::io; | |
use std::io::Write; | |
fn guessingMachine(guessValue: u16) { | |
loop { | |
let mut valueOfGuessStr = String::new(); | |
print!("You Guess : "); | |
io::stdout().flush(); | |
io::stdin() | |
.read_line(&mut valueOfGuessStr) | |
.expect("Something went wrong ( Input Guessing )"); | |
let valueToGuess: u16; | |
match valueOfGuessStr.trim().parse::<u16>() { | |
Ok(input) => { | |
if guessValue == input { | |
println!("You Correct"); | |
break; | |
} | |
else if guessValue < input { | |
println!("Down"); | |
} | |
else { | |
println!("Up"); | |
} | |
}, | |
Err(..) => println!("{} is not a number", valueOfGuessStr) | |
} | |
} | |
} | |
fn main() { | |
print!("--Up Down----Input A value you guess : "); | |
io::stdout().flush(); | |
let mut valueOfGuessStr = String::new(); | |
io::stdin() | |
.read_line(&mut valueOfGuessStr) | |
.expect("Something went wrong ( Input Int Value )"); | |
let valueToGuess: u16; | |
match valueOfGuessStr.trim().parse::<u16>() { | |
Ok(value) => { | |
println!("GAME START. YOU GUESS"); | |
guessingMachine(value); | |
}, | |
Err(..) => println!("{} is not a number", valueOfGuessStr) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment