Untitled
By: a guest | Mar 10th, 2010 | Syntax:
Python | Size: 2.21 KB | Hits: 60 | Expires: Never
//Michaela Patrice Morrissey
//Assignment 5 b
//February 24, 2010
//This program reads the file memberInfo.txt and runs in batch mode. It takes the information and computes information to display.
#include <stdio.h>
#include <math.h>
#define desiredbmi 25.0
#define METERS_PER_INCH .0254
#define POUNDS_PER_KILOGRAM 2.2046
int main()
{//begins program
//State variables
int member, m=1;
double inches, pounds, meters, kilograms, bmi, pweightgoal, kweightgoal;
char gender;
//Open file
FILE *bodyFile;
bodyFile = fopen("bodyFile.txt","r");
//Begin File Open Error Option
if (bodyFile == NULL)
printf ("Whoops! There was an error opening the file.\n");
//Begin Good open with else
else
{ //begins else
//print out header
printf("Mem# Height Weight Gender BMI Target Weight Classification\n");
//open a while statement
//scan info from file and store in variables defined
fscanf(bodyFile, "%d %lf %lf %c", &member, &inches, £s, &gender);
while (inches!=0)
{ //opens while
//print member number
printf("%03d", member);
//print height in inches
printf("%5.2f", inches);
//print weight in pounds
printf("%5.2f", pounds);
//print gender using switch
switch (gender)
{//opens switch
case 'M': printf("M");
break;
case 'F': printf("F");
break;
}//closes switch
//calculate bmi
//Convert height to meters
meters = inches * METERS_PER_INCH;
//Convert weight to kilograms
kilograms = pounds / POUNDS_PER_KILOGRAM;
//Caculate B.M.I.
bmi = kilograms / (meters * meters);
//print bmi
printf("%f", bmi);
//calculate target weight
//Caculate desired weight
kweightgoal = desiredbmi * meters * meters;
//Convert weight to pounds
pweightgoal = kweightgoal * POUNDS_PER_KILOGRAM;
//print target weight
printf("%f", pweightgoal);
//Print Classification using if-elseif-else statement PRINT LEFT JUSTIFIED!
if (bmi < 25)
printf("normal\n");
else if ( bmi >= 30)
printf("obese\n");
else
printf("overweight\n");
}//end while
}//end else
//close file
fclose(bodyFile);
return 0;
}