00:01
Okay, so in this question we want to write a c+ + program to calculate someone's bmi and classify the bmi of two people actually.
00:19
Okay, so we're going to first declare a function that will return, let's say, a float, and it will be called bmi, and it will take two intentsia.
00:34
As an input or not necessarily integer we can have float so it will be height and weight in this function bmi will return so the bmi so as simple as that it will be the way divided by the height square so in c plus plus to write a square you have many ways to square a number but personally i think we can just do the easy one which is we're going to multiply height by itself with parentheses in the right place and we are going to multiply all of that by 703 so that's the bmi of a person and if i compile this i have no compilation error the text is probably too small for you to see but there's no red so it's all good and then we're going to find someone's category or a class the class will be returned as an integer we're going to have a function called bmi class and it's going to take as an input of flow which is going to be our bmi and here i'm going to have to have i'll open my 30 brackets.
02:28
So if my bmi is below 18 .5, then its category is class 1, so i return 1 else if the weight is bmi greater than 18 .5 and bmi i'm gonna i'm a right greater or equal to 18 .5 and bmi lesser than 24 .9 then this is class two so i return now here i'm gonna start recycling my lines because i don't want to type everything all the time then the next class is between 25 so here i can actually put below 25 instead and greater or equal to 25 and lesser than 30 or 30.
03:55
You can't since we're working with float maybe it's better to put zero everything and this is class three and then if it's greater or equal to 30, then it's a class 4.
04:23
And i'm going to compile this.
04:28
Perfect.
04:30
And if, just to be, a good c+ + program should have a return value in case of error.
04:37
So we're going to return minus one, let's say, which will never happen, but it's always good practice to have a return value that's outside of if else statement.
04:52
So now what we need to do is just get the information of the first person.
04:58
So i'm going to use the c -out function.
05:02
I'm going to ask what's the message.
05:11
Enter person one's information.
05:18
And here i'm going to add stdn line.
05:22
I'm going to copy and paste this line.
05:24
Again when you code a lot of coding is simply copy -pasting so i'm going to have height and here i'm going to ask for weight now we need to declare a few variables to put that information in my first variable is going to be all is going to be they're going to be float and it's going to be a person's one height person's one weight and i'm going to need the same thing for the second person so i might as well declare it now.
06:09
The person to hide person to wait and here i'm going to use stdcn and i'm going to take in the person's one height and then the person's one i'm copy in this line here.
06:29
I'm going to take the person two, not the person one wait.
06:34
I'm going to write person one bmi and that is going to be i'm going to actually so i hope you have time to see to look at it you can always pause and come back i'm going to give my that i'm going to give myself some space in the main function it's going to be equal to bmi of e1 height and p1 weight and then i'm going to write bmi bmi class and it's going to be equal to bmi class class with no e of p1 bmi and here i need to write it as a load and this is going to be an integer and then i can output another message i'm going to copy paste this so i can reuse what i already have i'm going to simply write bmi equal and i'm going to write bmi.
08:02
Actually it's p1, p1 bmi...