Updated src/Ch02_Programming_a_Guessing_Game.md'.

This commit is contained in:
Hector PENG
2026-03-04 18:34:47 +08:00
parent 1edd5221f4
commit b65e63a501
4 changed files with 994 additions and 122 deletions

View File

@@ -4,3 +4,4 @@ version = "0.1.0"
edition = "2024"
[dependencies]
rand = "0.8.5"

View File

@@ -1,14 +1,20 @@
use std::io;
use rand::Rng;
fn main() {
println! ("猜猜这个数!");
let secret_number = rand::thread_rng().gen_range(1..=100);
println! ("秘密数字是:{secret_number}");
println! ("请输入你的猜数。");
let mut guess = String::new();
io::stdin()
.read_line(&mut guess)
.expect("读取行失败");
.expect("读取行失败");
println! ("你猜的是: {guess}");
}