#include <stdio.h>
int main( void )
{
double height, weight, bmi;
int bmievalcode;
while( 1 )
{
/* --> add code to input weight and height between here */
scanf("%lf %lf\n" , &weight &height)
bmi = weight * 703 / (height * height);
/* <-- and
here */
/* --> add code to calculate bmi and bmievalcode between here */
if (bmi <= 00.0){
bmievalcode = -1;
else if (bmi < 18.5)
bmievalcode = 1;
else if (bmi >= 18.5 && bmi < 25.0)
bmievalcode = 2;
else if (bmi >= 25.0 && bmi < 30.0)
bmievalcode = 3;
else (bmi >= 30)
bmievalcode
= 4;
/* <-- and
here */
/* bmievalcode:
* 1 = underweight
* 2 = normal
* 3 = overweight
* 4 = obese
*/
/* --> add code to print bmi and bmievalcode between here */
/* <-- and here */
}
while( 1 ) getchar( );
return 0;
}
what is the printf that can show:
bmi = %lf, evaluation is underweight
normal
overweight
obese
in one printf statement
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
int main( void )
{
double height, weight, bmi;
int bmievalcode;
char str[100];
while( 1 )
{
/* --> add code to input weight and height between
here */
printf("\nEnter weight and height
:");
scanf("%lf %lf" , &weight,&height);
bmi = weight * 703 / (height * height);
if (bmi <= 00.0){
bmievalcode = -1;}
else if(bmi<18.5)
bmievalcode = 1;
else if (bmi >= 18.5 && bmi < 25.0)
bmievalcode = 2;
else if (bmi >= 25.0 && bmi < 30.0)
bmievalcode = 3;
else if(bmi >= 30)
bmievalcode = 4;
switch(bmievalcode)
{
case 1:
strcpy(str,"underweight");
break;
case 2:
strcpy(str,"normal");
break;
case 3:
strcpy(str,"overweight");
break;
case 4:
strcpy(str,"obese");
break;
case -1:
exit(0);
}
printf("bmi=%lf,evaluation is
%s",bmi,str);
}
while( 1 )getchar();
return 0;
}
Get Answers For Free
Most questions answered within 1 hours.