Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranî)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
So let's solve this crazy exercise together.
And the first thing that we need to do is to create a great variable because we are going to read grades
from the user.
And we are going to store every time the graded we read inside of these variable and will assume that
the grades in these program are going to be of an integer type.
Right.
It's just an assumption.
So to calculate the average grade, we know that we need to some of the grades.
And that's exactly why we are going to create a some variable that sums all the grades that the user
inserts.
So eight total, let's call it total sum equals to zero.
And also, we are interested to know how many grades the user inserted because we do not know this much
in advance.
We only know it as we go.
So we will also create a variable called let's see how we will call it.
And let's call it grades.
Let's call it grades.
Count equals to zero.
And this variable will basically be present.
How many grades we have.
And these will represents the total sum of all the grades.
So if we would like to calculate the average grade in this case, we'll just think of the total sum
and divided by the grades count.
So now let's print some guiding message to the user.
So printout.
Please, please, please.
User, enter your grades, grades or enter a minus one.
Let's use it minus one to stop.
Okay.
A semicolon at the end.
And now we will use Scarn F scan F to read the grade and put it inside of the variable rate.
Okay.
Now we do not know in advance how many grades we are going to use.
So that's why we are going to use a while loop until we reach the stopping condition of grade equals
two minus one.
So as long as these condition, as long as grade is does not equal to minus one, we are going to execute
the loop body.
And in the loop body, we are going to sum the grades that we've inserted.
So total sum, total sum will be equals to the previous total sum, total sum, plus the grade that
we've inserted so far.
And we know that we found this sum.
And also we need to f whenever we read a new grade, we need to increment the grades count by one.
So weights count plus plus.
And now once we are done with this calculation, we are going simply to copy and paste these two lines
inside of our loop, because on each iteration we would like to read another grade from the user.
So we read the first grade here.
Then we come in added to the total sum and increase increment the grades count and then we read the
grade once again.
And there we go over and over again.
We run these while loop body until until this condition is not met.
So when the user will enter a grade, which equals two minus one.
And we read that at this line.
So whenever he does it, we are stepping out of these wire loop and we are proceeding with our program
to this line.
It's length 20.
And at least line, we can simply print out the result and we can say that.
Let's first of all, Brent, have you have you have entered percentage?
We want to specify how many grades the user has.
Insert that so far.
So grades up.
I'm sorry.
In certain grades.
Right.
And a backslash.
And at the end.
In here we are going to use the grades count.
All right.
So this message will represent how many grades the user has inserted.
And now we are going to print the main event of this calculator.
We are going to print of the average grade that the user will have.
And hopefully that will be a good grade.
Right.
So let's do something like this.
And your and your average every each grade is percentage.
And that percentage D because we are calculating are the result of that a vision between different numbers.
And the result may be of a floating point in time.
So that's why we are going to use percentage F.
And we are going to add a backslash and to skip the line.
And here we are going to calculate the average grade.
So it's basically the total sum divided, divided by the grades count.
And just one thing to mention here, we should specify the casting of double because we want the result
to be of a floating point types or in a double float.
Just float.
And.
There you go.
You can see that these programs will read all the grade until it reaches the stopping condition of minus
one, and Vannett calculates your average grade based on the number of grading provided.
OK, so let's try to build it and run it.
And in this example, we are going to use, let's say the first grade is going to be 80.
The second one is 90.
And the third one is a hundred.
We are just getting better and better.
So now let's stop the calculation using minus one or a stopping condition.
Right.
Or minus one just stops or we press minus one.
Press enter and your average grade.
You've entered three grades, right?
Yes, 80, 90 and 100.
And your average grade is 90.
So basically, guys, you developed a program that you can share with all of your friends, students,
colleagues, family, and give them these tool that you've created that they can use it on your own,
on their own.
It's awesome.
You're getting better and better, although in this chorus it's going to be in these kind of console
application of these black screen black, black, black and blank screen.
In the future courses that you are going to take, you're also going to develop some graphical user
interface that will help you to build much more complex and beautiful programs that you will be able
to use to sell, do whatever you like with them.
So thank you guys for watching.
You doing great.
You keep moving forward and you are becoming much better programmer than you were yesterday.
I'll see in the next video.
Oh.
Oh, and one last thing to mention here.
One less thing that hopefully will not let your computer crash.
Is that either user.
If it happens that a user inserts on the first attempt a grade of minus one, then you're going to have
a problem.
We are going to skip this while loop and we are going to come over here.
We are going to print that.
You've enter it zero grades, which is through.
But the problem is that when we are going to try to print the average grade result, we are going to
divide the total sum, which is zero.
We are going to divided by zero.
And that's a problem, right, guys?
So make sure you can handle this thing carefully by just maybe adding some condition beforehand.
Maybe doing something like this save on grades count does not equal to zero.
So then run this line, otherwise print some other message.
Okay.
So this is it for this video.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.