guessing game update

This commit is contained in:
2019-11-22 02:41:32 +00:00
parent 15a4aec9d1
commit 819ac2f8b3
4 changed files with 25 additions and 7 deletions

View File

@@ -1,2 +1,10 @@
/target
# Generated by Cargo
# will have compiled files and executables
/target/
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock
# These are backup files generated by rustfmt
**/*.rs.bk

View File

@@ -7,4 +7,5 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rand = "0.3.14"
rand = "0.4.0"
ferris-says = "0.1"

View File

@@ -1,19 +1,27 @@
use ferris_says::say;
use rand::Rng;
use std::io;
fn main() {
println!("Guess the number!");
let secret_number = rand::thread_rng().gen_range(1, 101);
let stdout = io::stdout();
let output = b"I will generate a number!";
let width = 28;
let mut writer = io::BufWriter::new(stdout.lock());
say(output, width, &mut writer).unwrap();
println!("The secret number is {}", secret_number);
println!("Please input your guess.");
let mut guess = String::new();
io::stdin()
.read_line(&mut guess)
.expect("Failed to read line");
println!("You guessed: {}", guess);
}
fn test(arg: String) -> String {
unimplemented!()
}