mirror of https://github.com/KaiserY/trpl-zh-cn
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
583 B
29 lines
583 B
3 years ago
|
// ANCHOR: all
|
||
|
use std::io;
|
||
|
// ANCHOR: ch07-04
|
||
|
use rand::Rng;
|
||
|
|
||
|
fn main() {
|
||
|
// ANCHOR_END: ch07-04
|
||
|
println!("Guess the number!");
|
||
|
|
||
|
// ANCHOR: ch07-04
|
||
|
let secret_number = rand::thread_rng().gen_range(1..101);
|
||
|
// ANCHOR_END: ch07-04
|
||
|
|
||
|
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);
|
||
|
// ANCHOR: ch07-04
|
||
|
}
|
||
|
// ANCHOR_END: ch07-04
|
||
|
// ANCHOR_END: all
|