In: Computer Science
please write it in printf and scanf please Please write it in c# program please and if possible no arrays only loops Loop Introduction Assignment Using the conditions below, write one program that calculates a person’s BMI. Your main() function will call functions 1, 2, and 3. Your program will contain three functions: Function #1: Will ask the user for their weight in pounds and their height in inches. Your function will convert the weight and height into Body Mass Index (BMI). The formula for converting weight into BMI is as follows: BMI = Weight * 703 / Height2 Your function will do this using a for loop and must display the BMI for 3 people, one at a time. In other words, display the BMI for person 1 before asking for the next person’s information. Function #2: This function will do the exact same thing as function #1, except you will use a do-while loop. Function #3: Using a while loop, write the same steps as function #1, but as an indefinite loop where we continue to ask the user if they would like to calculate the BMI again. Continue to do so until the user replies with either an ‘N’ or an ‘n’ Reserve Point Opportunity!! Complete the above program calling a fourth function that will calculate and return the BMI.
Code
#include <stdio.h>
void BMI_using_for();
void BMI_using_dowhile();
void BMI_using_while();
double calculateBMI(double,double);
int main(void) {
BMI_using_for();
BMI_using_dowhile();
BMI_using_while();
return 0;
}
void BMI_using_for()
{
double weight;
double height,BMI;
int i;
printf("Funciton using for loop\n\n");
for(i=1;i<=3;i++)
{
printf("Enter weight in pounds: ");
scanf("%lf",&weight);
printf("Enter height in inches: ");
scanf("%lf",&height);
BMI=calculateBMI(weight, height);
printf("Persont %d's BMI: %.2lf\n\n",i,BMI);
}
}
void BMI_using_dowhile()
{
double weight;
double height,BMI;
int i=1;
printf("Funciton using do..while() loop\n\n");
do
{
printf("Enter weight in pounds: ");
scanf("%lf",&weight);
printf("Enter height in inches: ");
scanf("%lf",&height);
BMI=calculateBMI(weight, height);
printf("Persont %d's BMI: %.2lf\n\n",i,BMI);
i+=1;
}while(i<=3);
}
void BMI_using_while()
{
double weight;
double height,BMI;
char again='y';
int i=1;
printf("Funciton using while loop\n\n");
while(1)
{
printf("Enter weight in pounds: ");
scanf("%lf",&weight);
printf("Enter height in inches: ");
scanf("%lf",&height);
BMI=calculateBMI(weight, height);
printf("Persont %d's BMI: %.2lf\n\n",i,BMI);
i++;
fflush(stdin);
printf("Do you want to continue (y/n)? ");
again=getchar();
if(again=='n'||again=='N')
break;
}
}
double calculateBMI(double weight,double height)
{
return (weight * 703) / (height*height);
}
output
If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.