Skip to content
Snippets Groups Projects
Commit 5709d612 authored by DevDoggo's avatar DevDoggo
Browse files

Minor cleanup.

parent d80cb763
No related branches found
No related tags found
No related merge requests found
...@@ -4,11 +4,10 @@ extern crate guessing_game; ...@@ -4,11 +4,10 @@ extern crate guessing_game;
use std::io; //standard in-out use std::io; //standard in-out
use std::cmp::Ordering; use std::cmp::Ordering;
use std::cmp::max;
use std::collections::HashMap; use std::collections::HashMap;
use std::io::Write; //seemingly needed to use io::stdout().flush()
use rand::Rng; use rand::Rng;
use std::io::Write; //seemingly needed to use io::stdout().flush()
use colored::*; use colored::*;
...@@ -28,7 +27,6 @@ fn get_input() -> Result<u32, String> { ...@@ -28,7 +27,6 @@ fn get_input() -> Result<u32, String> {
} }
} }
fn main() { fn main() {
println!("{}", "\n\nGuess the number or perish. :)".bold()); println!("{}", "\n\nGuess the number or perish. :)".bold());
...@@ -37,22 +35,15 @@ fn main() { ...@@ -37,22 +35,15 @@ fn main() {
println!("The secret number is: {}, but don't tell a soul.", secret_number); println!("The secret number is: {}, but don't tell a soul.", secret_number);
//Vector to hold all guesses, first to last. let mut guesses: Vec<(u32, String)>= Vec::new(); //Vector to hold all guesses, first to last.
let mut guesses: Vec<(u32, String)>= Vec::new(); let mut guess_pair: (u32, String); //Tuple
let mut guess_pair: (u32, String); let mut guess_hashmap = HashMap::new(); //Hashmap
let mut guess: u32; //Guess
//Hashmap let mut attempts = 0; //Attempts
let mut guess_hashmap = HashMap::new();
let mut guess: u32;
let mut attempts = 0;
loop{ loop{
match get_input() { match get_input() {
Ok(num) => { Ok(num) => guess = num,
println!("Number {}!", num);
guess = num;
}
Err(error) => { Err(error) => {
println!("Error {}!", error); println!("Error {}!", error);
continue; continue;
...@@ -61,12 +52,10 @@ fn main() { ...@@ -61,12 +52,10 @@ fn main() {
attempts += 1; attempts += 1;
//Vector guess_pair = (attempts, guess.to_string()); //Vector
guess_pair = (attempts, guess.to_string());
guesses.push(guess_pair); guesses.push(guess_pair);
//Hashmap guess_hashmap.insert(attempts, guess.to_string()); //Hashmap
guess_hashmap.insert(attempts, guess.to_string());
println!("\nYou guessed: {}!", guess); println!("\nYou guessed: {}!", guess);
print!("That's "); print!("That's ");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment