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
All right, welcome back.
Let's try to solve this exercise together.
So first of all, what I want you to notice is what will be the type of these functions?
So we said previously that the function is going to receive two values of a floating point type.
So this function will calculate the area in the area of the flow of the rectangle is just its way multiplied
by its height.
Right.
So two values multiplied, one by another.
And if both of them are are of a floating point type, then the result itself is also to go.
Going to be OWFI floating point.
Floating point type.
Floating point.
OK.
So let's say that the type of this function is going to be float and then we are going to name it as
find area.
OK.
And now it will receive two parameters.
So flowed.
Let's say we weave and float height.
And now we are going to write the functions bodies.
So let's do something like this.
And here we actually going to calculate the area of this rectangle.
So we said that the area may be calculated by multiplying with by each time.
So let's just for simplicity, create another variable and call it and call it area.
Okay.
And we know that area can be calculated by multiplying.
We by height.
Right.
Nothing complicated.
And and we are going to print the result of the screen or just return it.
And this is specified in the question itself.
We are just going to return the area without printing it.
So this function will be responsible for finding out the area and returning it to whoever calls it.
So return area.
Say my goal in the end.
So basically we can say that we are done with this function.
And now what we want to do is to write the main path and see how we can call this function and how we
can use it.
For now, it's just sitting idle here.
Right.
It's some guy that his name is Find Area and he awaits to receive two values.
And once he closes the door in his room, he will find the area and return.
But now it does nothing until we will call him, until we will approach him.
So that's exactly what we are going to do.
The main part.
So, first of all, let's create two variables here.
Let's call it also height and weave.
All right.
Let's do them something like height.
Rectangle, rectangle and weave.
Rick single.
All right.
I'm just using a slightly different name here in the main function.
And in the with in the in defined area function.
Because I want you to to to see that basically these variables here are local to them.
The main function in these variables with in height that these functional receives as parameters are
local to the find area function.
They are not the same.
OK.
We will talk about it more in the advanced sections where we are going to work with pointers and see
how we pass by value and pass by reference.
But that's for another section.
So now let's read these values from the user.
So print f enter with that.
OK.
And the user is going to answer.
He is square.
So percentage de and read the inside the single rectangle.
Why doesn't he total complete me.
OK.
And the same we are going to do for their height.
So answer height.
Right now.
Scarn f gonif percentage.
Knee height.
Height.
Rectangle.
Tingle.
Semicolon at the end.
And there you go.
So at this point we should have the both of these variables with and height.
And now what we want to do is to create.
Oh we.
Sorry about that.
We said that these values are going to be a free floating point.
So just change it to float in here instead of percentage.
Just use percentage.
F in percentage.
F.
Now what we want to do is to run this function, to use this function.
But we know that this function will return something and we want to store the result of this function
will return.
So we'll just create another variable and call it a float area.
Okay.
And now let's just use the function.
So area equals to find area.
Find area.
And we will pass as arguments.
These two values.
So first of all, rule plus this one.
And the second one is the height.
All right.
So now we know that this line at line 22.
We are calling the find area function.
These line.
Are executed and the result returned and assigned store the inside of this area variable.
And if you would like to print the area now, you're going to print the area, the area of your given
rectangle.
Is there a centage percentage half and backslash?
And at the end now, instead of this percentage effort, we are going to specify area.
Is that clear?
So let's try to build and run it.
Let's see an example.
So, oh, what happened?
Nothing really happened.
Why is that?
Why is that so?
No worries.
Guys, I found out what was the problem.
It's nothing related to you because I actually had a couple of other lessons here.
I had less than six, which I was recording also for you, and it was trying to build this last one
instead of this one.
So I fixed it up and we are ready to move on and try to build and run it once again.
So let's press build and run.
So enter with, let's say, five point zero and the height is going to be something like two point five.
So what we expect to receive here is basically we expect these mass edge of the area for your given
rectangle is.
And we expect the result of multiplying five by 2.5.
And the result expected is twin twelve point five.
If I'm not mistaken.
So that's what we expect to receive and to see on the console.
So we if we press answer, we are going to see these scary numbers right here.
And what what do they mean and where are they?
They come from.
And as you may be, if you were pretty much into this lesson your got you were about to see that this
ain't is the whole problem behind it, because we create two variables of an integer type and then read
from the user the inner values as they were a floating point.
So what do we have to fix?
Here is just these lines.
So float, float, change, these type of variables to be a float and now we can build in running once
again.
So 2.5 and five dot zero, we get twelve point five, which is the rectangle of this area.
So we can find the area for any given a rectangle that we will receive from the user.
We just need to receive the dimensions and we can provide this functionality, which is pretty cool,
right?
We can give these program to any student at high school which which struggles with his exams, and it
will help him a lot.
I'm just kidding, guys.
So thank you so, so much for watching.
And I'll see you in the next video.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.