Before we start, did you try solving the workbook yourself?
If not, please click the link in the resources folder and follow the instructions for this workbook.
Welcome to Workbook 5.8.
Task one is the story Secret number between one and five.
So we'll say end secret.
Let's set it to four.
And then task two is to set up a loop that keeps the user guessing until they get the number right.
So we chose a number between one and five.
Then we prompt the user to try and guess it.
So we will start by picking up their first choice.
We will say int guess is equal to skin dot next int.
And then after the user guesses, their first number will say while.
The guess is not equal to the secret.
We want to keep this loop running so long as what they guess does not match the secret, then we need
to prompt them to enter another guess.
So here we'll say guess again.
System dot dot, print, not print line.
Because if you look at the output, they guess beside the sentence that we print.
So we'll say, guess again.
And then said guess is equal to skin dot next and.
So this wide loop will only ever break if what they end up guessing equals our secret number.
Let us just visualize the runtime and see if our code is good.
All right, so the secret number is four.
I'm going to guess the number three.
The number that we guessed three does not equal the secret.
This evaluates the true so the wild loop runs, prompting us to guess again.
Next, it waits for me to enter another integer.
I'm going to guess number two.
A guess of two does not equal the secret number, so the while loop gets invoked again.
Guess again.
Next end prompts me to enter an integer.
I will enter the number one.
A guess of one does not equal the secret of four.
So this evaluates the true.
Running the while loop again.
This time I will guess the number for.
All right.
Four does equal the secret number that we chose.
This evaluates the false the while loop breaks because we guessed correctly.