Welcome back.
Previously, you learned how to generate random numbers by seeding the round package in his lecture,
I'm going to create the actual lucky number.
So let's get started.
OK, let's start by seeding the round package first by using the ever changing methods like this.
Donnelly's declare the guest number like this.
Then I'm going to have four or five times like this.
And instead of the follow up, I'm going to generate a random number between Zero and Geass plus one.
Then I'm going to check whether the random number is equal to the guest number.
If An equals to guess, OK, if so, then I'm going to print a message like this printed on.
You win.
And right after the loop, if the user couldn't be here, I'm going to print the lost message like this.
You lost again.
All right, let's try right the.
Here, even though the user wins, the loop doesn't end, and when it's done, it brings the loss message
here as well.
What's going on?
There is probably a bug, right?
So how can you solve this post video and think about it?
OK, to solve this one, the user wins the program short, and to do that, I can use the return statement
to return from the main function like this.
This way and the user wins, the program will be terminated and the loss message won't get displayed
at.
So let's run it again.
As you can see, Prince, the wind and lost messages correctly.
Now, let's refactor this program a little bit.
This convert, this magic number five here into a constant I'm going to type Maxitrans here now I'm
going to declare a new Konstanty.
By the way, Max Terms determines the difficulty of the game, actually.
So when it gets bigger, the game will be easier because there will be more chances for finding the
guest number right or when it gets smaller, game will be harder.
OK, now, instead of typing the number manually, let's get it from the command line.
First, I'm going to save the arguments into the ARC's variable like this.
Then I'm going to get the guest number from the ARC's.
OK, now I need to convert it into an integer number, right, to do that, I'm going to call the I
function.
OK, now this check for their.
If Aitor isn't new now, let's display an error message here.
OK, here, I also need to return so that when there is an error, the rest of the court wants run.
OK, all right, that's it.
That's right.
Now I'm going to guess five.
Good, eventually it works.
Now, let's try to run it with a negative number minus five.
Wow, that's crashed because the intown function doesn't accept negative numbers.
So what we can do.
So when the user picks a negative number, let's warn the user and quit from the program, right.
That's the solution.
Now I'm going to check whether the guess is negative like this.
Yes, is less than zero.
OK, and if so, I'm going to print a message like this, please pick a positive number now I need to
terminate the program, so I'm going to type return.
OK, the.
Let's try it again.
As you can see, it works perfectly now.
This time, let's try running it without any arguments whatsoever.
I do think that will happen now.
Kate, the sea.
It's crash a second since I didn't check the number of arguments passed to the program.
Right.
Let's do that now.
You know, I'm going to check whether there is an argument or not.
If not, then I'm going to print the usage message like this.
A No.
And I'm going to terminate from the program.
OK, let's try it again.
Good.
It works now.
I think that it be better to display a proper usage message.
First, I'm going to create a usage constant by using a real string literal like this.
Let's first print the name of the game and let's talk a little bit about the goal of the game.
Thumbprint, the teaser for the user.
All right, looks good here.
I've used the verb, I'll use it to print how many times the user will have.
Right, to print the usage message, I'm going to replace this shrink here.
With the usage constant like this now, the printed function will replace the verb inside the usage
constant with the value of the Maxitrans constant.
OK, OK, now let's try it and see how it works.
I think this looks better.
All right, that's all for this project.
Now it's your turn without solving problems with go, please don't expect that you'll be a gofer.
So I prepared a lot of exercise for you is important that you try doing time on your own.
First turn winner, first exercise, first term Vener, so if the first random number by the computer
matches the player's guess can print a special bonus message.
This will only happen if the computer picks the user's case number at the first time.
OK.
Second exercise is random messages, so at the end of the game, print random win and loss messages.
So currently, the program only displays one winning message, but I want you to display around them
winning messages each time the user wins.
OK.
Cool to do that, you can use a switch statement and the income function in its condition, no more
clues, sorry.
Currently, the player gets a small number, right, instead of one, let the player guess two numbers.
So when either of them are picked by the computer that print the winning message.
For the details and the rest of the exercises, please check out the loop exercises further in the course
repository.
OK, that's all for now.
All right, thank you for watching.
See in the next picture.