Back to articles
[Rust Guide] 2.1. Number Guessing Game Pt.1 - One Guess

[Rust Guide] 2.1. Number Guessing Game Pt.1 - One Guess

via Dev.toSomeB1oody

2.1.0. Key Points in This Article In this article, you will learn: Variable declaration Related functions Enumeration types Advanced usage of println!() ... 2.1.1. Game Objectives Generate a random number between 1 and 100 Prompt the player to input a guess (covered in this article) After guessing, the program will indicate whether the guess is too high or too low If the guess is correct, print a congratulatory message and exit the program 2.1.2. Code Implementation Step 1: Print the game name and prompt user input Build the main function. How to build functions and their format was covered in  1.2. Basic Understanding of Rust and Printing "Hello World" , so it won't be repeated here: fn main (){ } Use the  println!()  macro function to print text: fn main { println! ( "猜数游戏 Number Guessing Game" ); println! ( "猜一个数 Guess a number" ); } Step 2: Create a variable to store user input After prompting the user for input, the program needs a variable to store the user's input. This line of

Continue reading on Dev.to

Opens in a new tab

Read Full Article
3 views

Related Articles