1 00:00:00,270 --> 00:00:01,270 ‫Welcome back. 2 00:00:01,290 --> 00:00:05,010 ‫I hope you managed to get a solution for the challenge. 3 00:00:05,020 --> 00:00:08,460 ‫And now let's go ahead and see how I would do it. 4 00:00:08,700 --> 00:00:13,620 ‫Of course, there are multiple solutions to the challenge, and one of them is the one that I'm going 5 00:00:13,620 --> 00:00:14,380 ‫to show you. 6 00:00:14,400 --> 00:00:17,660 ‫So if you didn't manage to get that done, no worries. 7 00:00:17,670 --> 00:00:19,660 ‫I'm going to show you in this video. 8 00:00:19,680 --> 00:00:27,420 ‫So, first of all, what we need is an input variable and that one is going to be set to zero. 9 00:00:27,540 --> 00:00:32,940 ‫Then we need the amount of entries. 10 00:00:32,970 --> 00:00:38,100 ‫Or actually we could you call that count, which I set to zero as well. 11 00:00:38,280 --> 00:00:39,990 ‫But this time it's an integer. 12 00:00:40,170 --> 00:00:45,060 ‫Then we need to total, which I'm going to set to zero as well. 13 00:00:45,060 --> 00:00:47,880 ‫And then we need the current number. 14 00:00:47,970 --> 00:00:52,940 ‫Current number, and that one is going to be zero as well. 15 00:00:52,950 --> 00:00:59,730 ‫So these are going to be the variables that are important for our following program, because what we 16 00:00:59,730 --> 00:01:04,110 ‫need to check is what did the user enter or the teacher enter? 17 00:01:04,140 --> 00:01:05,520 ‫Was it a number? 18 00:01:05,550 --> 00:01:07,250 ‫If it was a number, we're fine. 19 00:01:07,260 --> 00:01:14,700 ‫Then let's increase the total, let's increase the count and well, let's parse the input and add that 20 00:01:14,700 --> 00:01:15,900 ‫to the total in general. 21 00:01:16,110 --> 00:01:20,730 ‫And the current number is going to be the input as a number. 22 00:01:21,240 --> 00:01:23,670 ‫So these are the four variables that are relevant here. 23 00:01:23,670 --> 00:01:31,320 ‫So let's create a while loop because I want to see if the input is not equal to minus one. 24 00:01:31,710 --> 00:01:38,400 ‫Because if that's the case, then that means that the teacher doesn't want to add any further values. 25 00:01:39,090 --> 00:01:43,260 ‫Now let's inform the teacher first what is required of him. 26 00:01:43,260 --> 00:01:44,820 ‫So let's write to him. 27 00:01:46,170 --> 00:01:57,450 ‫Last number was and then we have, for example, here our zero and current number. 28 00:01:57,930 --> 00:02:04,830 ‫So as we have not started well, as we have not entered anything yet, that's something that will be 29 00:02:04,830 --> 00:02:06,660 ‫shown with zero at the beginning. 30 00:02:06,660 --> 00:02:08,430 ‫So the current number will be zero. 31 00:02:08,430 --> 00:02:15,090 ‫And that's just a text that the teacher gets to get informed about all the different states that are 32 00:02:15,090 --> 00:02:16,060 ‫relevant to him. 33 00:02:16,080 --> 00:02:20,850 ‫Then please enter the next score. 34 00:02:21,390 --> 00:02:24,270 ‫That's just to inform him that she should enter scores. 35 00:02:24,360 --> 00:02:28,140 ‫Then console right line once again. 36 00:02:28,140 --> 00:02:33,540 ‫And now current amount of entries. 37 00:02:34,020 --> 00:02:36,510 ‫So he knows how many entries he has made. 38 00:02:37,080 --> 00:02:41,700 ‫And that should be again, our curly bracket zero. 39 00:02:41,850 --> 00:02:45,840 ‫And then that will be the count. 40 00:02:46,260 --> 00:02:49,260 ‫Now finally, console dot right line. 41 00:02:50,340 --> 00:02:57,910 ‫We need to inform the teacher as well that if he enters minus one, the whole application will be done. 42 00:02:57,940 --> 00:03:01,910 ‫Well, pretty much the calculation should be done and he gets the average. 43 00:03:01,920 --> 00:03:04,950 ‫So please enter minus one. 44 00:03:04,950 --> 00:03:15,330 ‫Once you are ready to calculate the average or once you have entered all the scores or something like 45 00:03:15,330 --> 00:03:15,780 ‫that. 46 00:03:15,870 --> 00:03:19,530 ‫So the text is what you of course have to choose yourself. 47 00:03:19,530 --> 00:03:21,050 ‫What do you want to inform him about? 48 00:03:21,060 --> 00:03:27,180 ‫Now we need the input, so let's get the input of the teacher and that's going to be console dot read 49 00:03:27,180 --> 00:03:27,960 ‫line. 50 00:03:28,170 --> 00:03:34,620 ‫Next, we need to check if the input is equal to minus one. 51 00:03:35,340 --> 00:03:37,470 ‫So minus one. 52 00:03:38,280 --> 00:03:42,360 ‫And we can either do that way or we can use the equals. 53 00:03:43,460 --> 00:03:47,180 ‫Equals minus one. 54 00:03:47,630 --> 00:03:51,710 ‫So what do we want to do if the teacher entered minus one? 55 00:03:51,740 --> 00:03:54,020 ‫Well, we want to calculate the average. 56 00:03:54,320 --> 00:03:57,230 ‫So let's go ahead, console right line. 57 00:03:57,500 --> 00:04:04,820 ‫And what I want to do here is just for easier viewing pleasure or better viewing pleasure. 58 00:04:04,970 --> 00:04:12,470 ‫To add this dotted line so that we can see this hash line, so that we can see the average a bit better 59 00:04:12,470 --> 00:04:16,490 ‫and see that all the steps before are separated. 60 00:04:16,820 --> 00:04:22,280 ‫Now we need to calculate the average of what was entered. 61 00:04:22,310 --> 00:04:30,110 ‫And that's something that we can do later on, calculate average and let the teacher know. 62 00:04:31,820 --> 00:04:33,500 ‫So that's something that we can do later. 63 00:04:33,500 --> 00:04:37,020 ‫But now there are some other things that we need to do as well. 64 00:04:37,040 --> 00:04:42,170 ‫So we need to, for example, check if the entry was actually a number. 65 00:04:42,200 --> 00:04:44,450 ‫So int try parse. 66 00:04:45,430 --> 00:04:48,370 ‫So if it worked that he parsed correctly. 67 00:04:48,370 --> 00:04:50,770 ‫And what is it that we want to parse? 68 00:04:50,770 --> 00:04:57,460 ‫Well, we need to parse the input and the output should be the current number. 69 00:04:58,450 --> 00:05:03,520 ‫So if it did work, we want to have the current number to be the output, right. 70 00:05:04,780 --> 00:05:14,410 ‫Next what we also want to check if the current number so current number is higher than zero and the 71 00:05:14,410 --> 00:05:23,200 ‫current number is lower than 21, because I just assumed that the score that the user can get is between 72 00:05:23,200 --> 00:05:24,520 ‫one and 20. 73 00:05:24,520 --> 00:05:28,630 ‫So that's simply what I'm making sure of here. 74 00:05:28,630 --> 00:05:29,800 ‫So I'm checking. 75 00:05:29,800 --> 00:05:32,050 ‫Is it actually something that worked? 76 00:05:32,050 --> 00:05:38,920 ‫So is it the number that he has entered and is the number between zero and or between one and 20? 77 00:05:38,920 --> 00:05:43,270 ‫And if that's the case, please go ahead and add that to the total. 78 00:05:43,330 --> 00:05:45,640 ‫So we have the total of zero so far. 79 00:05:45,640 --> 00:05:53,020 ‫And what we want to have now is total equals total plus current number. 80 00:05:54,280 --> 00:06:02,740 ‫So you can either do it that way, total equals total plus or you can plus equals current number. 81 00:06:03,220 --> 00:06:05,020 ‫So that's the shorter approach. 82 00:06:05,020 --> 00:06:08,170 ‫But the other one might be easier to read based on what you prefer. 83 00:06:08,200 --> 00:06:13,300 ‫So that will be executed if it can be parsed into a number. 84 00:06:13,300 --> 00:06:16,330 ‫So whatever the user has entered can be parsed into a number. 85 00:06:16,420 --> 00:06:18,640 ‫What if it wasn't the case? 86 00:06:18,640 --> 00:06:28,330 ‫So if it couldn't be parsed into a number or the number is higher than 21 or lower than zero, then 87 00:06:28,330 --> 00:06:37,960 ‫we want to check first if the entry is not equal minus one, because if he has entered minus one, then 88 00:06:37,960 --> 00:06:39,760 ‫we want to finish the program anyways. 89 00:06:39,760 --> 00:06:40,240 ‫Right. 90 00:06:40,870 --> 00:06:45,670 ‫So what we need to do here is to inform him. 91 00:06:45,670 --> 00:06:50,770 ‫Console right line, please. 92 00:06:52,920 --> 00:07:04,860 ‫Enter a value between one and 20 because this condition here will only be met if he entered something 93 00:07:04,860 --> 00:07:08,410 ‫that is not between one and 20. 94 00:07:08,430 --> 00:07:15,540 ‫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 95 00:07:15,540 --> 00:07:17,250 ‫what will be printed to him. 96 00:07:17,730 --> 00:07:22,290 ‫And then if that happens, we want to continue. 97 00:07:22,710 --> 00:07:26,310 ‫So we simply want to go to the next step. 98 00:07:27,270 --> 00:07:30,980 ‫And now we need to run something within our wild code. 99 00:07:30,990 --> 00:07:32,880 ‫So I'm going to make it a little smaller. 100 00:07:32,880 --> 00:07:40,800 ‫So we have everything on one screen and now we need to add the amount of iterations. 101 00:07:41,130 --> 00:07:48,000 ‫So here we need to increase the amount, which is our count. 102 00:07:49,650 --> 00:07:49,930 ‫Okay. 103 00:07:49,950 --> 00:07:55,590 ‫Amount of entries is our count, and I'm going to incriminate count here. 104 00:07:55,620 --> 00:07:57,360 ‫Why do I increment it here? 105 00:07:57,390 --> 00:08:00,900 ‫Well, I do so to make sure that it only is executed. 106 00:08:00,900 --> 00:08:05,940 ‫So we only increment count if we actually want to increment the count. 107 00:08:05,940 --> 00:08:12,930 ‫Because if you would do it without this, continue here, then it would even increase the amount of 108 00:08:12,930 --> 00:08:20,250 ‫entries if the number entered was not between zero or between one and 20, or if it was a different 109 00:08:20,250 --> 00:08:22,560 ‫kind of entry like the latter or something like that. 110 00:08:22,560 --> 00:08:26,490 ‫So here we make sure, okay, it only gets executed if everything worked fine. 111 00:08:26,490 --> 00:08:30,150 ‫So he entered a value that is good and we can go ahead. 112 00:08:31,510 --> 00:08:31,870 ‫All right. 113 00:08:31,870 --> 00:08:36,880 ‫So now one thing is left to do, and that is to calculate the average. 114 00:08:37,270 --> 00:08:38,320 ‫And how do we do that? 115 00:08:38,800 --> 00:08:41,320 ‫Well, we go ahead here. 116 00:08:41,710 --> 00:08:43,720 ‫We create a double. 117 00:08:44,920 --> 00:08:51,910 ‫And I use a double now because otherwise my average would be a whole number which is cut off and it's 118 00:08:51,910 --> 00:08:53,860 ‫not as precise as I want it to be. 119 00:08:53,950 --> 00:09:05,200 ‫So I'm going to call it average, which is a double of our total divided by a double of our count. 120 00:09:06,850 --> 00:09:12,490 ‫So what I say here is that the average is the total amount which is here. 121 00:09:13,360 --> 00:09:16,270 ‫Is incremented each time that we enter something. 122 00:09:16,300 --> 00:09:19,020 ‫Divided by the amount of entries that we have. 123 00:09:19,030 --> 00:09:24,820 ‫So that's basically the calculation or the formula to calculate the average. 124 00:09:25,600 --> 00:09:25,960 ‫Right. 125 00:09:25,960 --> 00:09:30,580 ‫Next, what we want to do is to write that onto the console. 126 00:09:30,580 --> 00:09:33,520 ‫So let's write it like that. 127 00:09:33,970 --> 00:09:44,800 ‫The average score of your students is and then we use the curly brackets zero again and hand over the 128 00:09:44,800 --> 00:09:47,020 ‫average and that's pretty much it. 129 00:09:47,020 --> 00:09:55,390 ‫So now we have our program which uses the input of the user and now we can go ahead and test that because 130 00:09:55,390 --> 00:09:56,230 ‫we should. 131 00:09:56,230 --> 00:09:57,940 ‫Oh, actually, we are missing one thing. 132 00:09:58,360 --> 00:10:05,080 ‫We are missing the red line towards the end because otherwise we don't see the result here. 133 00:10:05,080 --> 00:10:09,670 ‫So let's add that console that read or actually read. 134 00:10:09,850 --> 00:10:14,410 ‫Read the red line doesn't matter as long as we still get to see the code. 135 00:10:15,370 --> 00:10:16,270 ‫Let's run that. 136 00:10:17,220 --> 00:10:18,380 ‫Last number was zero. 137 00:10:18,390 --> 00:10:19,950 ‫Please enter the next score. 138 00:10:19,980 --> 00:10:21,570 ‫Current amount of entry zero. 139 00:10:21,570 --> 00:10:23,170 ‫Please enter minus one. 140 00:10:23,190 --> 00:10:25,350 ‫Once you are ready to calculate the average. 141 00:10:25,380 --> 00:10:25,650 ‫All right. 142 00:10:25,650 --> 00:10:26,520 ‫Let's go ahead. 143 00:10:26,520 --> 00:10:31,110 ‫Let's enter a just to check if our program still works. 144 00:10:31,410 --> 00:10:34,090 ‫Please enter a value between one and 20. 145 00:10:34,110 --> 00:10:34,560 ‫Perfect. 146 00:10:34,560 --> 00:10:35,670 ‫Last number was zero. 147 00:10:35,700 --> 00:10:37,200 ‫Please enter the next score. 148 00:10:37,230 --> 00:10:38,820 ‫Current amount of entries is zero. 149 00:10:38,820 --> 00:10:40,740 ‫So so far, everything is good. 150 00:10:40,740 --> 00:10:45,140 ‫Even if we enter some gibberish here, it still works perfectly. 151 00:10:45,150 --> 00:10:46,620 ‫So now let's enter ten. 152 00:10:47,380 --> 00:10:48,640 ‫Last number was ten. 153 00:10:48,860 --> 00:10:53,220 ‫Okay, now let's enter 15, 13, 12 and so forth. 154 00:10:53,230 --> 00:10:56,530 ‫So I'm just going to add some numbers here. 155 00:10:56,530 --> 00:11:00,820 ‫And if I add something like 31, it says, please enter a value between one and 20. 156 00:11:00,820 --> 00:11:01,660 ‫That's good. 157 00:11:01,690 --> 00:11:04,810 ‫So it knows if I do something wrong. 158 00:11:04,810 --> 00:11:12,040 ‫So if the teacher accidentally enters values that are incorrect, it will be stopped here. 159 00:11:12,040 --> 00:11:13,810 ‫So we have current amount of entries. 160 00:11:13,810 --> 00:11:18,400 ‫11 So I'm going to enter minus one and let's see what happens. 161 00:11:18,400 --> 00:11:26,050 ‫And it says the average score of your students is 11.09, zero nine, zero nine and so forth. 162 00:11:26,590 --> 00:11:27,190 ‫Great. 163 00:11:27,190 --> 00:11:32,860 ‫So here you see what we can do with the knowledge that we have gained so far. 164 00:11:32,860 --> 00:11:36,520 ‫We can create little average programs and you can do a lot more. 165 00:11:36,520 --> 00:11:41,290 ‫So we haven't seen how to use great user interfaces yet. 166 00:11:41,290 --> 00:11:44,230 ‫We are still working with consoles, but we'll get there. 167 00:11:44,230 --> 00:11:51,700 ‫So you will see how to create user interfaces with WPF, which is a tool to create great UI's with Visual 168 00:11:51,700 --> 00:11:52,390 ‫Studio. 169 00:11:52,390 --> 00:11:54,760 ‫So for now, I think that's good progress. 170 00:11:54,760 --> 00:11:58,210 ‫And in the next video, we're going to go ahead with the next topic. 171 00:11:58,210 --> 00:12:04,270 ‫So I hope to see you there and I hope you could solve that issue or that challenge or at least some 172 00:12:04,270 --> 00:12:05,140 ‫of the challenge. 173 00:12:05,140 --> 00:12:11,890 ‫And please let me know how you solved it so other students and I can compare what you've done and give 174 00:12:11,890 --> 00:12:15,190 ‫you some feedback or compared to what we have created ourselves. 175 00:12:15,190 --> 00:12:17,710 ‫So thanks a lot and see you in the next video.