From the course: First Look: Rust
Unlock the full course today
Join today to access over 22,700 courses taught by industry experts or purchase this course individually.
Comparing guess to secret number - Rust Tutorial
From the course: First Look: Rust
Comparing guess to secret number
- Now that we have the user input and the random number we can compare them. Let's go ahead and we can just go a little bit, so let's say print ln, welcome to the guessing game. And then let's generate the secret number right after that. And then let's print out the secret number for our testing before the user input sys, yes. Let me just delete this line and then now it's looking good. The first thing we do is to bring the ordering innum in to the scope. Let's write use, S-T-D, double colon, C-M-P, double colon, auditing. Here the S-T-D is the main library standard which in turn contains the cmp library, the computer's own library. So cmp is really a sub library inside std. Ordering is another innum just like this but the variance of ordering are less, greater, and equal. These are the three outcomes that are possible when you compare two values. We'll use the match operator to compare the user input guess with a generated secret number. Scroll down, once you've got the guess, just…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.