Question: Write a program that asks for the gender and the all the input appropriate to the gender, then calculate and display the Body Fat and

Write a program that asks for the gender and the all the input appropriate to the gender, then calculate and display the Body Fat and Body Fat Percentage.

Body fat formula for women:

  • A1 = Body Weight * 0.732 + 8.987
  • A2 = Wrist Measurement At Fullest Point / 3.140
  • A3 = Waist Measurement At Navel * 0.157
  • A4 = Hip Measurement At Fullest Point * 0.249
  • A5 = Forearm Measurement At Fullest Point * 0.434
  • B = A1 + A2 - A3 - A4 + A5
  • Body Fat = Body Weight - B
  • Body Fat Percentage = Body Fat * 100 / Body Weight

Body fat formula for men:

  • A1 = Body Weight * 1.082 + 94.42
  • A2 = Waist Measurement At Fullest Point * 4.15
  • B = A1 - A2
  • Body Fat = body Weight - B;
  • Body Fat Percentage = Body Fat * 100 / body Weight

Here's the output I'm trying to get:

Enter your gender (f|F|m|M): F

Enter body weight (in pounds): 120

Enter wrist measurement at fullest point (in inches): 5

Enter waist measurement at navel (in inches): 32

Enter hip measurement at fullest point (in inches): 36

Enter forearm measurement at fullest point (in inches): 23

Body fat: 25.586643 Body fat percentage: 21.322203

Here's the output i'm getting:

This program determines the body fat of a person.Enter your gender (f |F| m |M): f

Enter body weight (in pounds): 120

Enter wrist measurement at fullest point (in inches): 5

Enter waist measurement at navel (in inches): 32

Enter hip measurement at fullest point (in inches): 36

Enter forearm measurement at fullest point (in inches): 23

Body fat: -2.38936

Body fat percentage: -1.99113

Here's my Code:

#include

int main() {

char gender;

float a1, a2, a3, a4, a5;

float waistmeasurement, wristmeasurement, hipmeasurement, forarmmeasurement;

float B, bodyweight, Bodyfat, Bodyfatpercentage;

printf("This program determines the body fat of a person.Enter your gender (f|F|m|M): ");

scanf("%c", &gender);

printf(" ");

if(gender=='F' || gender=='f'){

printf("Enter body weight (in pounds): ");

scanf("%f", &bodyweight);

printf("Enter wrist measurement at fullest point (in inches): ");

scanf("%f", &wristmeasurement);

printf("Enter waist measurement at navel (in inches): ");

scanf("%f", &waistmeasurement);

printf("Enter hip measurement at fullest point (in inches): ");

scanf("%f", &hipmeasurement);

printf("Enter forearm measurement at fullest point (in inches): ");

scanf("%f", &forarmmeasurement);

a1=(bodyweight * 0.732) + 8.987;

a2=(wristmeasurement/3.140);

a3=(waistmeasurement * 0.157);

a4=(hipmeasurement * 0.249);

a5=(forarmmeasurement * 0.434);

B=a1+a2+a3+a4+a5;

Bodyfat = bodyweight - B;

Bodyfatpercentage=(Bodyfat*100)/bodyweight;

printf("Body fat: %.5lf ", Bodyfat);

printf("Body fat percentage: %.5lf ", Bodyfatpercentage);

}

else if(gender=='M' || gender=='m'){

printf("Enter body weight (in pounds): ");

scanf("%f", &bodyweight);

printf("Enter waist measurement at fullest point (in inches): ");

scanf("%f", &waistmeasurement);

a1=(bodyweight * 1.082) + 94.42;

a2=waistmeasurement * 4.15;

B=a1-a2;

Bodyfat = bodyweight - B;

Bodyfatpercentage=(Bodyfat*100)/bodyweight;

printf("Body fat: %.5lf ", Bodyfat);

printf("Body fat percentage: %.5lf ", Bodyfatpercentage);

}

else{

printf("Invalid gender code.");

return(0);

}

return(0);

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!