Question: Why can I not get my if function to read the letters m and f in my C++ code? The program skips the first section

Why can I not get my if function to read the letters m and f in my C++ code? The program skips the first section for the male input and computation; and it moves on to the else for the female section, the math follows through correctly for the female section. How do I make the if function read f or m in a if (gender == m), else (gender == f)

#include

#include

#include

#include

using namespace std;

int main()

{

char gender;

double bodWeight;

double WaistMeas;

double m;

double f;

cout << fixed << showpoint << setprecision(2);

cout << "Enter the gender, m for male, f for female: ";

cin >> gender;

cout << endl;

if (gender == m)

{

double A1 = (bodWeight * 1.082) + 94.42;

double A2 = WaistMeas * 4.15;

double B = A1 - A2;

double BodyFat = bodWeight - B;

double FatPerc = (BodyFat * 100) / bodWeight;

cout << "Enter body weight here: ";

cin >> bodWeight;

cout << endl;

cout << "Enter waist measurement here: ";

cin >> WaistMeas;

cout << endl;

cout << "body fat of the person: " << BodyFat << endl;

cout << "body fat percentage of the person: " <<

FatPerc << endl;

}

else (gender == f);

{

double A1, A2, A3, A4, A5, B;

double bodWeight;

double WristMeas;

double WaistMeas;

double HipMeas;

double ForearmMeas;

double BodyFat;

double FatPerc;

cout << "Enter body weight here: ";

cin >> bodWeight;

cout << endl;

cout << "Enter the wrist measurement at fullest point of the person: ";

cin >> WristMeas;

cout << endl;

cout << "Enter the waist measurement at naval of the person: ";

cin >> WaistMeas;

cout << endl;

cout << "Enter the hip measurement at fullest point of the person: ";

cin >> HipMeas;

cout << endl;

cout << "Enter forearm measurement here: ";

cin >> ForearmMeas;

cout << endl;

A1 = (bodWeight * 0.732) + 8.987;

A2 = WristMeas / 3.140;

A3 = WaistMeas * 0.157;

A4 = HipMeas * 0.249;

A5 = ForearmMeas* 0.434;

B = A1 + A2 - A3 - A4 + A5;

BodyFat = bodWeight - B;

FatPerc = (BodyFat * 100 / bodWeight);

cout << "Body fat of the person: " << BodyFat << endl;

cout << "Body fat percentage of the person: " <<

FatPerc << endl;

}

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!