Page 1 of 1

โปรแกรมคำนวณค่าน้ำหนักและส่วนสูง หรือค่า BMI

Posted: 05/10/2013 7:25 am
by nokroo
#include <stdio.h>
#include <conio.h>
int main()
{
int i;
char Name[30];
float Age[30];
char Sex[30];
float BMI[30];
float Height[30];
float Weight[30];

for(i = 0; i < 30 ; i++){
printf("\n\nEnter Your Name[%d]: ",i+1);
scanf("%s",&Name[i]);
printf("\n\nEnter Your Age[%d]: ",i+1);
scanf("%f",&Age[i]);
printf("\n\nEnter Your Sex[%d]: ",i+1);
scanf("%s",&Sex[i]);
printf("\n\nEnter Your Height[%d]: ",i+1);
scanf("%f",&Height[i]);
printf("\n\nEnter Your Weight[%d]: ",i+1);
scanf("%f",&Weight[i]);

BMI[i] = Weight[i]/(Height[i]/100*Height[i]/100);

if(BMI[i] >= 40){
printf("\n\nName[%d]: %s",i+1,Name);
printf("\n\nAge[%d]: %f",i+1,Age[i]);
printf("\n\nBMI[%d] = %f >> Obesity is the most advanced.\n",i+1,BMI[i]);
}
else if(BMI[i] >= 35.0 && BMI[i] <= 39.9){
printf("\n\nName[%d]: %s",i+1,Name);
printf("\n\nAge[%d]: %f",i+1,Age[i]);
printf("\n\nBMI[%d] = %f >> Obesity Step 2.\n",i+1,BMI[i]);
}
else if(BMI[i] >= 28.5 && BMI[i] <= 34.9){
printf("\n\nName[%d]: %s",i+1,Name);
printf("\n\nAge[%d]: %f",i+1,Age[i]);
printf("\n\nBMI[%d] = %f >> Obesity Step 1.\n",i+1,BMI[i]);
}
else if(BMI[i] >= 23.5 && BMI[i] <= 28.4){
printf("\n\nName[%d]: %s",i+1,Name);
printf("\n\nAge[%d]: %f",i+1,Age[i]);
printf("\n\nBMI[%d] = %f >> Overweight then.\n",i+1,BMI[i]);
}
else if(BMI[i] >= 18.5 && BMI[i] <= 23.4){
printf("\n\nName[%d]: %s",i+1,Name);
printf("\n\nAge[%d]: %f",i+1,Age[i]);
printf("\n\nBMI[%d] = %f >> Weight in the normal range.\n",i+1,BMI[i]);
}
else if(BMI[i] < 18.5){
printf("\n\nName[%d]: %s",i+1,Name);
printf("\n\nAge[%d]: %f",i+1,Age[i]);
printf("\n\nBMI[%d] = %f >> Weight below the threshold.\n",i+1,BMI[i]);
}
}
getch();
}

Image