Code:
/*This program converts your Mass and Height into Body Mass Index(BMI).*/
int main(int argc, char ** argv)
{
// Mainline Variable Declarations
FILE * output = stdout;
FILE * input = stdin;
//Declareation of Variables.
double Kilograms;
int CentiMetres;
double BMI;
int Age;
char * FName[20];
char * LName[20];
char * Gender[1];
fprintf(output,"1 = Enter Your First Name Initial? \n"); fflush(output);
fprintf(output,"2 = Enter Your Last Name?\n") fflush(output);
fprintf(output,"3 = Enter Your Age?\n") fflush(output);
fprintf(output,
//******************************************************************
//Enter first name.
fprintf(output,"--------------------------\n"); fflush(output);
fprintf(output,"Enter Your first name: "); fflush(output);
//input first name.
fscanf(input,"%s",&FName);
//******************************************************************
//Enter last name.
fprintf(output,"--------------------------\n"); fflush(output);
fprintf(output,"Enter Your last name: "); fflush(output);
//input last name.
fscanf(input,"%s",&LName);
//******************************************************************
//Enter the Age.
fprintf(output,"--------------------------\n"); fflush(output);
fprintf(output,"Enter Your Age Between 18 to 100: "); fflush(output);
// input age.
fscanf(input,"%d",&Age);
// Reasonable value for age.
while ((Age < 18 )||( Age > 100))
{
//This error message will appear if the number enter in not with in the range.
fprintf(output,"--------------------------\n"); fflush(output);
fprintf(output,"Error\nYour Age Must be Between 18 to 100: ");fflush(output);
fscanf(input,"%s",&Age);
}
//******************************************************************
//Enter Gender
fprintf(output,"--------------------------\n");
fprintf(output,"Enter Your Gender (M/F): \n"); fflush(output);
//input Gender.
fscanf(input,"%s",&Gender);
// If Gender its not M/F/-,then error message should appear.
while (Age !=(M)||Age !=(F)||Age !=(-))
{
//This error message will appear if the number enter in not within the range.
fprintf(output,"--------------------------\n"); fflush(output);
fprintf(output,"Gender must be M(male)/F(female)/-: ");fflush(output)
fscanf(input,"%d",&Gender);
}
//******************************************************************
// Enter Mass in Kilograms.
fprintf(output,"--------------------------\n"); fflush(output);
fprintf(output,"Enter weight in kilograms: "); fflush(output);
// input Mass Kilograms.
fscanf(input,"%lf",&Kilograms);
//Reasonable value for Weight.
while ((Kilograms < 25) || (Kilograms > 230))
{
//This error message will appear if the number enter in not within the range.
fprintf(output,"--------------------------\n"); fflush(output);
fprintf(output,"Error\nYour Weight must be in between 25 to 230 ",Kilograms);
fscanf(input,"%lf",&Kilograms);
}
//******************************************************************
// Enter height in CentiMetres.
fprintf(output,"--------------------------\n"); fflush(output);
fprintf(output,"Enter Height in Centimetres: "); fflush(output);
// input height CentiMetres.
fscanf(input,"%d",&CentiMetres);
{
//Reasonable Value for Height.
while ((CentiMetres < 70) || (CentiMetres > 220))
{
//This error message will appear if the number enter in not within the range.
fprintf(output,"--------------------------\n"); fflush(output);
fprintf(output,"Error\nYour Height must be in between 70 to 220 Cm: ",CentiMetres);
fscanf(input,"%d",&CentiMetres);
}
}
//******************************************************************
// Calculation to get BMI.
fprintf(output,"--------------------------\n"); fflush(output);
BMI = ( Kilograms / ( CentiMetres * CentiMetres ) * 10000);
//******************************************************************
// output results.
fprintf(output,"%s",FName);
fprintf(output," %s",LName);
fprintf(output," is %c",Gender);
fprintf(output," and is age %d",Age);
fprintf(output," and weight %lf",Kilograms);
fprintf(output," Kg and %d",CentiMetres);
fprintf(output," Cm Tall and has BMI of %.2f",BMI);
//******************************************************************
if (BMI<18.50)
{
fprintf(output," This is a Weight status of Underweight\n",BMI);
}
else if (BMI<24.99)
{
fprintf(output," This is a Weight status of Normal weight\n",BMI);
}
else if (BMI<29.99)
{
fprintf(output," This is a Weight status of Overwright\n",BMI);
}
else
{
fprintf(output," This is a Weight status of Obese\n",BMI);
}
}