I'm trying to write a program for class which calls 3 functions in main which is get input, do calculations, and print output. I also need to be using pointers which I have no understanding of how to use.
so far my attempt is just giving me headaches. Can anyone steer me in the right direction?
Code:
#include <stdio.h>
#include <math.h>
#define INCHES_FT 12
#define CENT_INCH 2.54
#define CENT_METER 100
#define LB_KG 2.2
void getInput();
void doCalculations(int feet, double inches, double pounds, int age);
double printOutput(double bmi, double bmr);
double convertToInch(int feet, double inches);
double convertToCent(double inInches);
double convertToMeter(double inCent);
double convertToKG(double pounds);
double calculateBMI(double inKG, double inMeter);
double calculateBMR(double inKG, double inCent, int age);
int main(void)
{
getInput();
doCalculations(&feet, &inches, £s, &age,);
printOutput(double bmi, double bmr);
return 0;
}
void getInput()
{
int feet;
double inches;
double pounds;
int age;
printf("Enter height in feet & inches: ");
scanf("%d %lf", &feet, &inches);
printf("Enter weight in pounds: ");
scanf("%lf", £s);
printf("Enter age in years (whole # only): ");
scanf("%d\n\n", &age);
}
void doCalculations(int *feet, double *inches, double *pounds, int *age)
{
double inInches;
double inCent;
double inMeter;
double inKG;
double bmi;
double bmr;
inInches = convertToInch(*feet, *inches);
inCent = convertToCent(inInches);
inMeter = convertToMeter(inCent);
inKG = convertToKG(*pounds);
bmi = calculateBMI(inKG, inMeter);
bmr = calculateBMR(inKG, inCent, *age);
}
double convertToInch(int feet, double inches)
{
return (feet*INCHES_FT + inches);
}
double convertToCent(double inInches)
{
return (inInches*CENT_INCH);
}
double convertToMeter(double inCent)
{
return (inCent/CENT_METER);
}
double convertToKG(double pounds)
{
return (pounds/LB_KG);
}
double calculateBMI(double inKG, double inMeter)
{
return inKG/pow(inMeter, 2);
}
double calculateBMR(double inKG, double inCent, int age)
{
return 66 + (13.75 * inKG) + (5 * inCent) – (6.8 * age);
}
double printOutput(double bmi, double bmr)
{
printf("The BMI = %.3lg", bmi);
printf("The BMR (Male) = %.3lg", bmr);
return 0;
}