[C++] Need help with this body fat calculating program 08-02-2015, 03:54 PM
#1
Can somebody tell me what I did wrong? I'm not getting correct answers. This should be giving me the body fat and body fat percentage. I'd appreciate some help ASAP.
It would probably be too late by the time I get an answer, but what the heck. XD
Problem:
It would probably be too late by the time I get an answer, but what the heck. XD
Problem:
Quote:One way to determine how healthy a person is by measuring the body fat
of the person. The formulas to determine the body fat for female and male
are as follows:
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 = wrist measurement 4.15
B = A1 – A2
Body fat = body weight – B
Body fat percentage = body fat 100 / body weight
Write a program to calculate the body fat of a person
Code:
#include <iostream>
using namespace std;
int main()
{
char gender;
double bodyweight, wrist, waist, hip, forearm, B, bodyfat, bfPercentage, A1, A2, A3, A4, A5;
bodyfat = bodyweight - B;
bfPercentage = (bodyfat * 100) / bodyweight;
cout << "Input gender (m/f): ";
cin >> gender;
switch (gender)
{
case 'F':
case 'f':
cout << "Enter body weight: ";
cin >> bodyweight;
cout << "Enter wrist measurement (at fullest point): ";
cin >> wrist;
cout << "Enter waist measurement (at navel): ";
cin >> waist;
cout << "Enter hip measurement (at fullest point): ";
cin >> hip;
cout << "Enter forearm measurement (at fullest point): ";
cin >> forearm;
A1 = (bodyweight * 0.723) + 8.987;
A2 = (wrist) / 3.140;
A3 = (waist) * 0.157;
A4 = (hip) * 0.249;
A5 = (forearm) * 0.434;
B = A1 + A2 - A3 - A4 + A5;
cout << "Your body fat is: " << bodyfat << endl
<< "Body fat percentage: " << bfPercentage << "%";
break;
case 'M':
case 'm':
cout << "Enter body weight: ";
cin >> bodyweight;
cout << "Enter wrist measurement (at fullest point): ";
cin >> wrist;
A1 = (bodyweight * 1.082) + 94.42;
A2 = wrist * 4.14;
B = A1 - A2;
cout << "Your body fat is: " << bodyfat << endl
<< "Body fat percentage: " << bfPercentage << "%";
break;
default:
cout << "Invalid gender.";
}
return 0;
}![[Image: dHJ4Beo.gif]](http://i.imgur.com/dHJ4Beo.gif)
Hidden Lesson: Reactions are always instinctive whereas responses are always well thought of.










![[+]](https://sinister.ly/images/modern/collapse_collapsed.png)














![[Image: CDUAq9d.png]](http://i.imgur.com/CDUAq9d.png)