Login Register


[C++] Need help with this body fat calculating program filter_list
Author
Message
RE: [C++] Need help with this body fat calculating program #8
(08-02-2015, 11:13 PM)Dyme Wrote: You realize you're performing calculations using the "bodyweight" and "B" variables before they are even assigned a value, right?

Oh, ok. I thought I can just put it there so I can use it later on.

Is this fine now, or is there a better way to write it? Should I initiate bodyfat and bfPercentage in both cases or I can just initialize it in the first case? I could try it myself, but I'm not home, I don't have a compiler. I'd appreciate an answer. Smile
Code:
#include <iostream> using namespace std; int main() { char gender; double bodyweight, wrist, waist, hip, forearm, B, bodyfat, bfPercentage, A1, A2, A3, A4, A5; 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; bodyfat = bodyweight - B; bfPercentage =(bodyfat * 100) / bodyweight; 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; bodyfat = bodyweight - B; bfPercentage =(bodyfat * 100) / bodyweight; cout << "Your body fat is: " << bodyfat << endl << "Body fat percentage: " << bfPercentage << "%"; break; default: cout << "Invalid gender."; } return 0; }
[Image: dHJ4Beo.gif]
Hidden Lesson: Reactions are always instinctive whereas responses are always well thought of.

Reply





Messages In This Thread
RE: [C++] Need help with this body fat calculating program - by OversouL - 08-03-2015, 02:11 PM



Users browsing this thread: