[Rust Guide] 2.3. Number Guessing Game Pt.3 - Comparing Input and Random Number
2.3.0. Key Points of This Section In this section, you will learn: How to use match Shadowing Type casting The Ordering type 2.3.1. Game Objectives Generate a random number between 1 and 100 Prompt...
![[Rust Guide] 2.3. Number Guessing Game Pt.3 - Comparing Input and Random Number](https://media2.dev.to/dynamic/image/width=1200,height=627,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvmwcbt08reg0mxf9sx66.png)
Source: DEV Community
2.3.0. Key Points of This Section In this section, you will learn: How to use match Shadowing Type casting The Ordering type 2.3.1. Game Objectives Generate a random number between 1 and 100 Prompt the player to enter a guess After the guess, the program will tell whether the guess is too big or too small (covered in this section) If the guess is correct, print a congratulatory message and exit the program 2.3.2. Code Implementation This is the code written up to the previous article: use std::io; use rand::Rng; fn main() { let range_number = rand::thread_rng().gen_range(1..101); println!("Number Guessing Game"); println!("Guess a number"); let mut guess = String::new(); io::stdin().read_line(&mut guess).expect("Could not read the line"); println!("The number you guessed is:{}", guess); println!("The secret number is: {}", range_number); } Step 1: Data Type Conversion From the code, we can see that the variable guess is of string type, while range_number is of type i32 (a signed 32