Skip to content

Instantly share code, notes, and snippets.

@SnowyPainter
Created October 28, 2019 08:33
Show Gist options
  • Save SnowyPainter/3015a370a8834b3539442dfec7232ccc to your computer and use it in GitHub Desktop.
Save SnowyPainter/3015a370a8834b3539442dfec7232ccc to your computer and use it in GitHub Desktop.
It's my first rust project.
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