‫Welcome back.
‫I hope you managed to get a solution for the challenge.
‫And now let's go ahead and see how I would do it.
‫Of course, there are multiple solutions to the challenge, and one of them is the one that I'm going
‫to show you.
‫So if you didn't manage to get that done, no worries.
‫I'm going to show you in this video.
‫So, first of all, what we need is an input variable and that one is going to be set to zero.
‫Then we need the amount of entries.
‫Or actually we could you call that count, which I set to zero as well.
‫But this time it's an integer.
‫Then we need to total, which I'm going to set to zero as well.
‫And then we need the current number.
‫Current number, and that one is going to be zero as well.
‫So these are going to be the variables that are important for our following program, because what we
‫need to check is what did the user enter or the teacher enter?
‫Was it a number?
‫If it was a number, we're fine.
‫Then let's increase the total, let's increase the count and well, let's parse the input and add that
‫to the total in general.
‫And the current number is going to be the input as a number.
‫So these are the four variables that are relevant here.
‫So let's create a while loop because I want to see if the input is not equal to minus one.
‫Because if that's the case, then that means that the teacher doesn't want to add any further values.
‫Now let's inform the teacher first what is required of him.
‫So let's write to him.
‫Last number was and then we have, for example, here our zero and current number.
‫So as we have not started well, as we have not entered anything yet, that's something that will be
‫shown with zero at the beginning.
‫So the current number will be zero.
‫And that's just a text that the teacher gets to get informed about all the different states that are
‫relevant to him.
‫Then please enter the next score.
‫That's just to inform him that she should enter scores.
‫Then console right line once again.
‫And now current amount of entries.
‫So he knows how many entries he has made.
‫And that should be again, our curly bracket zero.
‫And then that will be the count.
‫Now finally, console dot right line.
‫We need to inform the teacher as well that if he enters minus one, the whole application will be done.
‫Well, pretty much the calculation should be done and he gets the average.
‫So please enter minus one.
‫Once you are ready to calculate the average or once you have entered all the scores or something like
‫that.
‫So the text is what you of course have to choose yourself.
‫What do you want to inform him about?
‫Now we need the input, so let's get the input of the teacher and that's going to be console dot read
‫line.
‫Next, we need to check if the input is equal to minus one.
‫So minus one.
‫And we can either do that way or we can use the equals.
‫Equals minus one.
‫So what do we want to do if the teacher entered minus one?
‫Well, we want to calculate the average.
‫So let's go ahead, console right line.
‫And what I want to do here is just for easier viewing pleasure or better viewing pleasure.
‫To add this dotted line so that we can see this hash line, so that we can see the average a bit better
‫and see that all the steps before are separated.
‫Now we need to calculate the average of what was entered.
‫And that's something that we can do later on, calculate average and let the teacher know.
‫So that's something that we can do later.
‫But now there are some other things that we need to do as well.
‫So we need to, for example, check if the entry was actually a number.
‫So int try parse.
‫So if it worked that he parsed correctly.
‫And what is it that we want to parse?
‫Well, we need to parse the input and the output should be the current number.
‫So if it did work, we want to have the current number to be the output, right.
‫Next what we also want to check if the current number so current number is higher than zero and the
‫current number is lower than 21, because I just assumed that the score that the user can get is between
‫one and 20.
‫So that's simply what I'm making sure of here.
‫So I'm checking.
‫Is it actually something that worked?
‫So is it the number that he has entered and is the number between zero and or between one and 20?
‫And if that's the case, please go ahead and add that to the total.
‫So we have the total of zero so far.
‫And what we want to have now is total equals total plus current number.
‫So you can either do it that way, total equals total plus or you can plus equals current number.
‫So that's the shorter approach.
‫But the other one might be easier to read based on what you prefer.
‫So that will be executed if it can be parsed into a number.
‫So whatever the user has entered can be parsed into a number.
‫What if it wasn't the case?
‫So if it couldn't be parsed into a number or the number is higher than 21 or lower than zero, then
‫we want to check first if the entry is not equal minus one, because if he has entered minus one, then
‫we want to finish the program anyways.
‫Right.
‫So what we need to do here is to inform him.
‫Console right line, please.
‫Enter a value between one and 20 because this condition here will only be met if he entered something
‫that is not between one and 20.
‫So if it's a letter, if it's a whole text, if it's a different number like 25 or whatever, so that's
‫what will be printed to him.
‫And then if that happens, we want to continue.
‫So we simply want to go to the next step.
‫And now we need to run something within our wild code.
‫So I'm going to make it a little smaller.
‫So we have everything on one screen and now we need to add the amount of iterations.
‫So here we need to increase the amount, which is our count.
‫Okay.
‫Amount of entries is our count, and I'm going to incriminate count here.
‫Why do I increment it here?
‫Well, I do so to make sure that it only is executed.
‫So we only increment count if we actually want to increment the count.
‫Because if you would do it without this, continue here, then it would even increase the amount of
‫entries if the number entered was not between zero or between one and 20, or if it was a different
‫kind of entry like the latter or something like that.
‫So here we make sure, okay, it only gets executed if everything worked fine.
‫So he entered a value that is good and we can go ahead.
‫All right.
‫So now one thing is left to do, and that is to calculate the average.
‫And how do we do that?
‫Well, we go ahead here.
‫We create a double.
‫And I use a double now because otherwise my average would be a whole number which is cut off and it's
‫not as precise as I want it to be.
‫So I'm going to call it average, which is a double of our total divided by a double of our count.
‫So what I say here is that the average is the total amount which is here.
‫Is incremented each time that we enter something.
‫Divided by the amount of entries that we have.
‫So that's basically the calculation or the formula to calculate the average.
‫Right.
‫Next, what we want to do is to write that onto the console.
‫So let's write it like that.
‫The average score of your students is and then we use the curly brackets zero again and hand over the
‫average and that's pretty much it.
‫So now we have our program which uses the input of the user and now we can go ahead and test that because
‫we should.
‫Oh, actually, we are missing one thing.
‫We are missing the red line towards the end because otherwise we don't see the result here.
‫So let's add that console that read or actually read.
‫Read the red line doesn't matter as long as we still get to see the code.
‫Let's run that.
‫Last number was zero.
‫Please enter the next score.
‫Current amount of entry zero.
‫Please enter minus one.
‫Once you are ready to calculate the average.
‫All right.
‫Let's go ahead.
‫Let's enter a just to check if our program still works.
‫Please enter a value between one and 20.
‫Perfect.
‫Last number was zero.
‫Please enter the next score.
‫Current amount of entries is zero.
‫So so far, everything is good.
‫Even if we enter some gibberish here, it still works perfectly.
‫So now let's enter ten.
‫Last number was ten.
‫Okay, now let's enter 15, 13, 12 and so forth.
‫So I'm just going to add some numbers here.
‫And if I add something like 31, it says, please enter a value between one and 20.
‫That's good.
‫So it knows if I do something wrong.
‫So if the teacher accidentally enters values that are incorrect, it will be stopped here.
‫So we have current amount of entries.
‫11 So I'm going to enter minus one and let's see what happens.
‫And it says the average score of your students is 11.09, zero nine, zero nine and so forth.
‫Great.
‫So here you see what we can do with the knowledge that we have gained so far.
‫We can create little average programs and you can do a lot more.
‫So we haven't seen how to use great user interfaces yet.
‫We are still working with consoles, but we'll get there.
‫So you will see how to create user interfaces with WPF, which is a tool to create great UI's with Visual
‫Studio.
‫So for now, I think that's good progress.
‫And in the next video, we're going to go ahead with the next topic.
‫So I hope to see you there and I hope you could solve that issue or that challenge or at least some
‫of the challenge.
‫And please let me know how you solved it so other students and I can compare what you've done and give
‫you some feedback or compared to what we have created ourselves.
‫So thanks a lot and see you in the next video.