1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
double maxHeartRate(int x);
double BMR(char sex, int weight, int inches, int x);
double BMR(char sex, int weight, int inches, int x, int alev);
double BMI(double lbs, double inch);
void displayResult(string calculation, double result);
int main()
{
int age;
int weight;
int inches;
int activityLevel;
char gender;
string calculation;
//Explanation of Program
cout << "This program will give you the choice to compute one of the following: " << endl;
cout << "-Maximum Heart Rate" << endl;
cout << "-Basal Metabolic Rate" << endl;
cout << "-Adjusted Basal Metabolic Rate" << endl;
cout << "-Body Mass Index" << endl;
cout << endl;
cout << "Please enter your information, then press return" << endl;
cout << endl;
//Stores age variable
cout << "Enter your age (in years), then press return: " << endl;
cin >> age;
//stores gender
cout << "Enter your gender by typing M for male or F for female: " << endl;
cin >> gender;
//stores weight
cout << "Enter your weight (in pounds), then press return: " << endl;
cin >> weight;
//stores height (inches)
cout << "Enter your height (in inches), then press return: " << endl;
cin >> inches;
//stores activity level
cout << "Please enter your activity level:" << endl;
cout << "Press 1 for Sedentary" << endl;
cout << "Press 2 for Somewhat Active (exercise occasionally)" << endl;
cout << "Press 3 for Active (exercise 3-4 days per week)" << endl;
cout << "Press 4 for Highly Active (exercise every day)" << endl;
cin >> activityLevel;
//user selections which calculation to perform
cout << "Please enter which calculation you wish to perform --" << endl;
cout << "To calculate your maximum heart rate enter MHR" << endl;
cout << "To calculate your basal metabolic rate enter BMR" << endl;
cout << "To calculate your adjusted basal metabolic rate enter ABMR" << endl;
cout << "To calculate your body mass index enter BMI" << endl;
cin >> calculation;
displayResult("MHR", maxHeartRate(age));
cout << endl;
displayResult("BMR", BMR(gender, weight, inches, age));
cout << endl;
displayResult("ABMR", BMR(gender, weight, inches, age, activityLevel));
cout << endl;
displayResult("BMI", BMI(weight, inches));
cout << endl;
system("pause");
return 0;
}
double maxHeartRate(int x)
{
return 205.8 - (0.685 * x);
}
double BMR(char sex, int weight, int inches, int x)
{
if (sex == 'F')
{
return 655 + (4.35 * weight) + (4.7 * inches) - (4.7 * x);
}
else if (sex == 'M')
{
return 66 + (6.23 * weight) + (12.7 * inches) - (6.8 * x);
}
else
{
cout << "You have entered an invalid character" << endl;
}
}
double BMI(double lbs, double inch) //BMI = ( Weight in Pounds / ( Height in inches x Height in inches ) ) x 703
{
return (lbs / (inch * inch)) * 703;
}
double BMR(char sex, int weight, int inches, int x, int alev) //Computes users adjusted BMR (BMR * activity level)
{
if (sex == 'F')
{
switch (alev)
{
case 1: return (655 + (4.35 * weight) + (4.7 * inches) - (4.7 * x)) * 1.2;
break;
case 2: return (655 + (4.35 * weight) + (4.7 * inches) - (4.7 * x)) * 1.3;
break;
case 3: return (655 + (4.35 * weight) + (4.7 * inches) - (4.7 * x)) * 1.4;
break;
case 4: return (655 + (4.35 * weight) + (4.7 * inches) - (4.7 * x)) * 1.5;
}
}
if (sex == 'M')
{
switch (alev)
{
case 1: return (66 + (6.23 * weight) + (12.7 * inches) - (6.8 * x)) * 1.2;
break;
case 2: return (66 + (6.23 * weight) + (12.7 * inches) - (6.8 * x)) * 1.3;
break;
case 3: return (66 + (6.23 * weight) + (12.7 * inches) - (6.8 * x)) * 1.4;
break;
case 4: return (66 + (6.23 * weight) + (12.7 * inches) - (6.8 * x)) * 1.5;
break;
}
}
else
{
cout << "You have entered an invalid character" << endl;
}
}
void displayResult(string calculation, double result)
{
if (calculation == "MHR")
{
cout << "Your maximum heart rate is: " << result;
}
else if (calculation == "BMR")
{
cout << "Your BMR is: " << result;
}
else if (calculation == "ABMR")
{
cout << "Your adjusted BMR is: " << result;
}
else if (calculation == "BMI")
{
cout << "Your BMI is: " << result;
}
}
| |