Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,360 --> 00:00:03,630
So let's solve this crazy exercise together.
2
00:00:03,750 --> 00:00:09,450
And the first thing that we need to do is to create a great variable because we are going to read grades
3
00:00:09,450 --> 00:00:10,200
from the user.
4
00:00:10,470 --> 00:00:17,940
And we are going to store every time the graded we read inside of these variable and will assume that
5
00:00:18,030 --> 00:00:21,720
the grades in these program are going to be of an integer type.
6
00:00:21,840 --> 00:00:22,200
Right.
7
00:00:22,440 --> 00:00:23,580
It's just an assumption.
8
00:00:23,730 --> 00:00:28,050
So to calculate the average grade, we know that we need to some of the grades.
9
00:00:28,110 --> 00:00:35,370
And that's exactly why we are going to create a some variable that sums all the grades that the user
10
00:00:35,370 --> 00:00:35,970
inserts.
11
00:00:36,030 --> 00:00:40,830
So eight total, let's call it total sum equals to zero.
12
00:00:41,250 --> 00:00:48,300
And also, we are interested to know how many grades the user inserted because we do not know this much
13
00:00:48,300 --> 00:00:48,900
in advance.
14
00:00:48,930 --> 00:00:50,700
We only know it as we go.
15
00:00:51,210 --> 00:00:55,620
So we will also create a variable called let's see how we will call it.
16
00:00:56,050 --> 00:00:59,670
And let's call it grades.
17
00:01:00,390 --> 00:01:01,230
Let's call it grades.
18
00:01:01,230 --> 00:01:03,030
Count equals to zero.
19
00:01:03,210 --> 00:01:05,360
And this variable will basically be present.
20
00:01:05,400 --> 00:01:07,080
How many grades we have.
21
00:01:07,320 --> 00:01:10,680
And these will represents the total sum of all the grades.
22
00:01:10,950 --> 00:01:17,730
So if we would like to calculate the average grade in this case, we'll just think of the total sum
23
00:01:17,730 --> 00:01:20,010
and divided by the grades count.
24
00:01:20,130 --> 00:01:23,690
So now let's print some guiding message to the user.
25
00:01:23,700 --> 00:01:24,670
So printout.
26
00:01:25,530 --> 00:01:27,870
Please, please, please.
27
00:01:27,870 --> 00:01:35,400
User, enter your grades, grades or enter a minus one.
28
00:01:35,430 --> 00:01:38,160
Let's use it minus one to stop.
29
00:01:38,910 --> 00:01:39,350
Okay.
30
00:01:39,550 --> 00:01:41,070
A semicolon at the end.
31
00:01:41,490 --> 00:01:48,780
And now we will use Scarn F scan F to read the grade and put it inside of the variable rate.
32
00:01:49,190 --> 00:01:49,480
Okay.
33
00:01:49,800 --> 00:01:53,280
Now we do not know in advance how many grades we are going to use.
34
00:01:53,370 --> 00:02:01,080
So that's why we are going to use a while loop until we reach the stopping condition of grade equals
35
00:02:01,080 --> 00:02:02,490
two minus one.
36
00:02:02,610 --> 00:02:09,390
So as long as these condition, as long as grade is does not equal to minus one, we are going to execute
37
00:02:09,390 --> 00:02:10,410
the loop body.
38
00:02:10,530 --> 00:02:14,820
And in the loop body, we are going to sum the grades that we've inserted.
39
00:02:15,120 --> 00:02:23,310
So total sum, total sum will be equals to the previous total sum, total sum, plus the grade that
40
00:02:23,310 --> 00:02:24,870
we've inserted so far.
41
00:02:24,960 --> 00:02:26,970
And we know that we found this sum.
42
00:02:27,000 --> 00:02:34,620
And also we need to f whenever we read a new grade, we need to increment the grades count by one.
43
00:02:34,680 --> 00:02:36,360
So weights count plus plus.
44
00:02:36,530 --> 00:02:43,680
And now once we are done with this calculation, we are going simply to copy and paste these two lines
45
00:02:43,890 --> 00:02:50,670
inside of our loop, because on each iteration we would like to read another grade from the user.
46
00:02:50,700 --> 00:02:52,460
So we read the first grade here.
47
00:02:52,800 --> 00:02:58,560
Then we come in added to the total sum and increase increment the grades count and then we read the
48
00:02:58,560 --> 00:02:59,490
grade once again.
49
00:02:59,820 --> 00:03:02,510
And there we go over and over again.
50
00:03:02,520 --> 00:03:08,520
We run these while loop body until until this condition is not met.
51
00:03:08,640 --> 00:03:12,480
So when the user will enter a grade, which equals two minus one.
52
00:03:12,570 --> 00:03:14,520
And we read that at this line.
53
00:03:15,060 --> 00:03:20,340
So whenever he does it, we are stepping out of these wire loop and we are proceeding with our program
54
00:03:20,340 --> 00:03:21,180
to this line.
55
00:03:21,270 --> 00:03:22,220
It's length 20.
56
00:03:22,410 --> 00:03:27,240
And at least line, we can simply print out the result and we can say that.
57
00:03:27,330 --> 00:03:33,500
Let's first of all, Brent, have you have you have entered percentage?
58
00:03:33,990 --> 00:03:37,230
We want to specify how many grades the user has.
59
00:03:37,260 --> 00:03:38,430
Insert that so far.
60
00:03:38,760 --> 00:03:40,650
So grades up.
61
00:03:41,010 --> 00:03:41,820
I'm sorry.
62
00:03:42,560 --> 00:03:43,940
In certain grades.
63
00:03:43,950 --> 00:03:44,290
Right.
64
00:03:44,760 --> 00:03:45,930
And a backslash.
65
00:03:45,930 --> 00:03:46,650
And at the end.
66
00:03:46,680 --> 00:03:50,070
In here we are going to use the grades count.
67
00:03:50,670 --> 00:03:51,100
All right.
68
00:03:51,120 --> 00:03:55,920
So this message will represent how many grades the user has inserted.
69
00:03:56,130 --> 00:03:59,850
And now we are going to print the main event of this calculator.
70
00:03:59,880 --> 00:04:05,520
We are going to print of the average grade that the user will have.
71
00:04:05,610 --> 00:04:07,590
And hopefully that will be a good grade.
72
00:04:07,650 --> 00:04:07,980
Right.
73
00:04:08,010 --> 00:04:10,620
So let's do something like this.
74
00:04:10,650 --> 00:04:16,980
And your and your average every each grade is percentage.
75
00:04:17,010 --> 00:04:24,850
And that percentage D because we are calculating are the result of that a vision between different numbers.
76
00:04:24,870 --> 00:04:27,890
And the result may be of a floating point in time.
77
00:04:28,020 --> 00:04:30,710
So that's why we are going to use percentage F.
78
00:04:31,630 --> 00:04:35,970
And we are going to add a backslash and to skip the line.
79
00:04:36,120 --> 00:04:39,100
And here we are going to calculate the average grade.
80
00:04:39,150 --> 00:04:45,730
So it's basically the total sum divided, divided by the grades count.
81
00:04:47,280 --> 00:04:53,250
And just one thing to mention here, we should specify the casting of double because we want the result
82
00:04:53,250 --> 00:04:56,730
to be of a floating point types or in a double float.
83
00:04:57,000 --> 00:04:57,720
Just float.
84
00:04:58,500 --> 00:04:59,520
And.
85
00:04:59,760 --> 00:05:00,510
There you go.
86
00:05:00,630 --> 00:05:06,930
You can see that these programs will read all the grade until it reaches the stopping condition of minus
87
00:05:06,930 --> 00:05:14,460
one, and Vannett calculates your average grade based on the number of grading provided.
88
00:05:14,970 --> 00:05:17,400
OK, so let's try to build it and run it.
89
00:05:17,560 --> 00:05:24,500
And in this example, we are going to use, let's say the first grade is going to be 80.
90
00:05:24,810 --> 00:05:26,420
The second one is 90.
91
00:05:26,910 --> 00:05:28,800
And the third one is a hundred.
92
00:05:28,830 --> 00:05:30,840
We are just getting better and better.
93
00:05:31,200 --> 00:05:37,740
So now let's stop the calculation using minus one or a stopping condition.
94
00:05:37,740 --> 00:05:38,070
Right.
95
00:05:38,400 --> 00:05:41,220
Or minus one just stops or we press minus one.
96
00:05:41,250 --> 00:05:44,470
Press enter and your average grade.
97
00:05:44,490 --> 00:05:47,070
You've entered three grades, right?
98
00:05:47,310 --> 00:05:49,360
Yes, 80, 90 and 100.
99
00:05:49,710 --> 00:05:52,430
And your average grade is 90.
100
00:05:52,770 --> 00:05:59,250
So basically, guys, you developed a program that you can share with all of your friends, students,
101
00:05:59,250 --> 00:06:04,800
colleagues, family, and give them these tool that you've created that they can use it on your own,
102
00:06:05,010 --> 00:06:05,850
on their own.
103
00:06:06,030 --> 00:06:06,690
It's awesome.
104
00:06:06,690 --> 00:06:12,600
You're getting better and better, although in this chorus it's going to be in these kind of console
105
00:06:12,600 --> 00:06:17,550
application of these black screen black, black, black and blank screen.
106
00:06:17,730 --> 00:06:22,500
In the future courses that you are going to take, you're also going to develop some graphical user
107
00:06:22,500 --> 00:06:29,940
interface that will help you to build much more complex and beautiful programs that you will be able
108
00:06:29,940 --> 00:06:33,900
to use to sell, do whatever you like with them.
109
00:06:33,990 --> 00:06:35,520
So thank you guys for watching.
110
00:06:35,550 --> 00:06:36,660
You doing great.
111
00:06:36,690 --> 00:06:44,370
You keep moving forward and you are becoming much better programmer than you were yesterday.
112
00:06:44,490 --> 00:06:45,600
I'll see in the next video.
113
00:06:45,720 --> 00:06:46,220
Oh.
114
00:06:46,700 --> 00:06:50,520
Oh, and one last thing to mention here.
115
00:06:50,760 --> 00:06:56,400
One less thing that hopefully will not let your computer crash.
116
00:06:56,670 --> 00:06:58,550
Is that either user.
117
00:06:58,590 --> 00:07:05,370
If it happens that a user inserts on the first attempt a grade of minus one, then you're going to have
118
00:07:05,370 --> 00:07:05,940
a problem.
119
00:07:05,940 --> 00:07:10,290
We are going to skip this while loop and we are going to come over here.
120
00:07:10,290 --> 00:07:11,700
We are going to print that.
121
00:07:11,730 --> 00:07:14,640
You've enter it zero grades, which is through.
122
00:07:14,670 --> 00:07:22,680
But the problem is that when we are going to try to print the average grade result, we are going to
123
00:07:22,770 --> 00:07:26,000
divide the total sum, which is zero.
124
00:07:26,010 --> 00:07:28,380
We are going to divided by zero.
125
00:07:28,530 --> 00:07:30,660
And that's a problem, right, guys?
126
00:07:31,260 --> 00:07:38,370
So make sure you can handle this thing carefully by just maybe adding some condition beforehand.
127
00:07:38,490 --> 00:07:44,520
Maybe doing something like this save on grades count does not equal to zero.
128
00:07:44,790 --> 00:07:49,710
So then run this line, otherwise print some other message.
129
00:07:49,740 --> 00:07:50,100
Okay.
130
00:07:50,250 --> 00:07:52,130
So this is it for this video.
11379
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.