dimanche 28 février 2016

Calculating Mass Index and For loop?

Please bear with me all, as this is my first programming class. So what I'm trying to do is to calculate BMI based on an input of height and weight, and to determine whether the weight is overweight or obese based on the BMI calculated. I'm also required to include this for loop what would run the function four times, but I can't even get it to run properly once. I'm not sure if it's because I'm using the wrong type of returnType or if my formula for calculating BMI is off. Please help!

#include <stdio.h>
FILE *csis;

int calculateBMI(double height,double weight);

int main(void) {
int i;
double BMI, height, weight;

csis = fopen("csis.txt", "w");
for (i = 1; i <= 4; ++i); {
    int calculateBMI(double height, double weight);
}

printf("Enter your height (in inches) and weight (in pounds):\n");
fprintf(csis,"Enter your height (in inches) and weight (in pounds):\n");
scanf("%d %d", &height, &weight);
printf("Your BMI is: %.2f\n", BMI);
fprintf(csis,"Your BMI is: %.2f\n", BMI);
return BMI;


if (BMI < 18.5) {
    printf("The calculated Body Mass Index is Underweight.\n");
    fprintf(csis,"The calculated Body Mass Index is Underweight.\n");
}
else if (BMI < 25.0) {
    printf("The calculated Body Mass Index is Normal.\n");
    fprintf(csis,"The calculated Body Mass Index is Normal.\n");
}
else if (BMI < 30.0) {
    printf("The calculated Body Mass Index is Overweight.\n");
    fprintf(csis,"The calculated Body Mass Index is Overweight.\n");
}
else {
    printf("The calculated Body Mass Index is Obese.\n");
    fprintf(csis,"The calculated Body Mass Index is Obese.\n");

    fclose(csis);
    return BMI;
}
}

// Calculates BMI given the weight and height.
// Returns the Body Mass Index

int calculateBMI(double height, double weight) {
    double BMI;

    BMI = (weight * 703) / (height * height);
return BMI;
}

Aucun commentaire:

Enregistrer un commentaire