guessing game update
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
target/*
|
||||
10
rust-book/chapter-1/guessing_game/.gitignore
vendored
10
rust-book/chapter-1/guessing_game/.gitignore
vendored
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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!()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user