Program description:
The user is prompted for his/her age, height, weight, and gender.
The users info goes through an if/else statement ( Boolean expression ) and calculates his/here bmr based on his/her gender.
The user is then told how many chocolate bars he or she can eat without gaining any weight :-)
Any suggestions or comments for improvment are welcome!
#include <iostream>
using namespace std;
int main()
{
// "magic formula" to force any amount of decimal points for value type double
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(1);
// Variable Declarations: chocolate variable is already set to 230.
double weight, height, bmr, total_bars, age, chocolate(230);
char gender;
// Program Intro - explaining to the user what the program will do.
cout << "This program calculates how many choclate bars you can eat without gainging any weight.
";
// Inputs - prompting the user for all of his/her information required to enter into our formula
cout << "Please enter your weight in pounds:
";
cin >> weight;
cout << "Please enter your height in inches:
";
cin >> height;
cout << "Please enter your age in years:
";
cin >> age;
cout << "Male or Female? Enter m for male, f for female.
";
cin >> gender;
// Processing - an if/else statement was required to seperate the two different possible gender formulas.
// Take note that without the ' ' around the m, the if/else statement will not work.
if (gender == 'm')
bmr = 66 + (6.3 * weight) + (12.9 * height) - (6.8 * age);
else
bmr = 655 + (4.3 * weight) + (4.7 * height) - (4.7 * age);
total_bars = (bmr/chocolate);
// Output - giving the user his/her result. Maybe they should eat something healthier, like an apple.
cout << "You can eat a total of
" << total_bars << " chocolate bars without gaining any weight! :smile:
";
return 0;
}