← go back
use rand::Rng; // import rand
use std::cmp::Ordering; // import ordering
use std::io; // import io
// nothing here
fn main() { // start `main` function
println! // print the text
("Guess the number!"); // about what this program does
// nothing here
let secret_number = // get secret number
rand // on module rand
::thread_rng() // get this thread's RNG
.gen_range(1..=100); // generate number between 1 and 100
// nothing here
loop { // i feel loopy
println! // print the text
("Please input your guess."); // to ask for guess
// nothing here
let mut guess = // define mutable variable `guess`
String // of type String
::new(); // a blank value
// why are there so many blank lines
io::stdin() // get standard input
.read_line // read a line there
(&mut guess) // borrow guess to write it there
.expect // when it failed
("Failed to read line"); // panic with this text
// i'm lonely
let guess: u32 = // define a variable `guess`
match // we will be matching
guess // the guess
.trim() // without the spaces
.parse() // parsed into a u32
{ // MATCHING START!
Ok(num) // if ok
=> // then
num, // return that num
Err(_) // if error
=> // then
continue, // ignore
}; // MATCHING STOP?
// i'm all alone
match // we will be matching
guess // the guess
.cmp // compared with
(&secret_number) // the secret number
{ // MATCHING START!
Ordering // if
::Less // it's less
=> // then
println! // print the text
("Too small!"), // about it being less
Ordering // if
::Greater // it's greater
=> // then
println! // print the text
("Too big!"), // about it being greater
Ordering // if
::Equal // it's equal
=> // then
{ // do this
println! // print the text
("Too small!"); // about winning
break; // end program
} // doing done
}; // MATCHING STOP?
} // my loopy wore off
} // end `main` function
someone made a code that’s commented in every line so I made it worse
Aug 16, 2024, 1:53 PM
2 0 0
Comments