### BMR calculator. Need help. again

1. Write a C++ program to calculate Basal Metabolic Rate and total calorie needs. Use the Harris Benedict equation to calculate calorie needs.
2. The program must use at least three functions or procedures.
3. (See the additional handouts for BMR and Total Calories)
4. The input to the program will be the weight in pounds, the height in inches, the age, and the character 'm' for male and 'f' for female. Read the input data in a procedure using call by reference.
5. The output of the program will be the BMR and Total Calories Needs for each data set. The program must use an end-of-file loop to get credit. Also, echo print the input data for each data set. Write the information in formatted columns with heads.

INPUT:
(FIle included)

OUTPUT:
it looks exactly like the input

Step 1: calculating the BMR

BMR calculation for men : BMR = 66.5 + ( 13.75 x weight in kg ) + ( 5.003 x height in cm ) - ( 6.755 x age in years )
BMR calculation for men : BMR = 66 + ( 6.23 x weight in pounds ) + < 12.7 x height in inches ) - ( 6.76 x age in years )
BMR calculation for women : BMR = 665.1 + ( 9.563 x weight in kg ) + ( 1.850 x height in cm ) - ( 4.676 x age in years )
BMR calculation for women : BMR = 655 + ( 4.35 x weight in pounds ) + ( 4.7 x height in inches ) - (4.7 x age in years )

Step 2: applying the Harris-Benedict Principle

Little to no exercise ------------------------------------------------------------------- Daily calories needed = BMR x 1.2
Light exercise (1-3 days per week)------------------------------------------------- Daily calories needed = BMR x 1.375
Moderate exercise ( 3-5 days per week )------------------------------------------- Daily calories needed = BMR x 1.55
Heavy exercise ( 6-7 days per week ) ----------------------------------------------- Daily calories needed = BMR x 1.725
Very heavy exercise ( twice per day, extra heavy workouts ) -------------------- Daily calories needed = BMR x 1.9

Applications for weight loss

Using the formulae above, a 24-year old, 80 kg male who is 180 cm would have a BMR of 1900. If he exercised moderately, he would multiply his BMR
by his activity level (1900 x 1.55) to determine daily calorie requirements, which would be 2945 kcal per day to keep his weight at 80 kg. This may seem like a high calorie intake, but his activity level requires it. This individual would exercise normally but not lose weight. The same individual without the exercise routine would only be able to consume 2273 kcal per day without gaining weight. The US Department of Health and Human Services Daily Value Guidelines provides figures that support the above example.

Using the Harris-Benedict Equation, individuals can take a mathematical approach to weight loss. There are 3500 calories in 1lb (0..45) of body fat. Using the Harris-Benedict Principle, if someone has a daily allowance of 2500 calories, but he reduces his intake to 2000, then they calculations show a 1 pound loss every 7 days.

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788`` ``````#include #include #include #include #include #include using namespace std; int main () { ifstream inFile; inFile.open("input.txt"); int calories; int weightInPounds, heightInInches, ageInYears, activityLevel, totalCalories; char gender; int bmr; cout << "Weight Height Age Gender Activity Level BMR Total Calories" << endl; while (inFile); { cout << "------ ------ --- ------ -------------- --- --------------" << endl << endl; //Height //Weight //gender //activity level inFile >> activityLevel; char gender; if (gender == 'm') { float bmrsumM = 66 + (6.23 * weightInPounds) + (12.7 * heightInInches) - (6.76 * ageInYears); float activitysum; //selects which activity level the user is switch (activityLevel) { case 1: activitysum = bmrsumM * 1.2; break; case 2: activitysum = bmrsumM * 1.375; break; case 3: activitysum = bmrsumM * 1.55; break; case 4: activitysum = bmrsumM * 1.725; break; case 5: activitysum = bmrsumM * 1.9; break; } //end selection } else { float bmrsumF = 655 + (4.35 * weightInPounds) + (4.7 * heightInInches) - (4.7 * ageInYears); float activitysum; switch(activityLevel) { case 1: activitysum = bmrsumF * 1.2; break; case 2: activitysum = bmrsumF * 1.375; break; case 3: activitysum = bmrsumF * 1.55; break; case 4: activitysum = bmrsumF * 1.725; break; case 5: activitysum = bmrsumF * 1.9; break; } } } cout << "press enter to exit" << endl; cin.ignore(); cin.get(); return 0; } ``````

Last edited on
Do you have a question or problem with your code?

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259`` ``````#include #include #include #include using namespace std; class Patient { public: double weight,height,BMR,principle; int age,active; char system,gender; char FName[256]; char LName[256]; char Hash[256]; // A line in the .txt file that is ---------------------- }; void mBMRcalc(Patient patient[],int I) { string System; switch(patient[I].system) { case 'M': case 'm': patient[I].BMR = 66.5 + (13.75 * patient[I].weight) + (5.003 * patient[I].height) - (6.557 * patient[I].age); break; case 'U': case 'u': patient[I].BMR = 66 + (6.23 * patient[I].weight) + (12.7 * patient[I].height) - (6.76 * patient[I].age); break; default: cout << "This patient's system was invalid!" << endl; break; } switch(patient[I].active) { case 1: patient[I].principle = patient[I].BMR * 1.2; break; case 2: patient[I].principle = patient[I].BMR * 1.375; break; case 3: patient[I].principle = patient[I].BMR * 1.55; break; case 4: patient[I].principle = patient[I].BMR * 1.725; break; case 5: patient[I].principle = patient[I].BMR * 1.9; break; default: cout << "Invalid activity level!" << endl; break; } cout << "Patient's name was " << patient[I].FName << " " << patient[I].LName << endl; cout << "The system used was "; switch(patient[I].system) { case 'U': case 'u': System = "US system"; cout << System << endl; break; case 'M': case 'm': System = "Metric system"; cout << System << endl; break; default: System = "Invalid"; cout << System << endl; break; } cout << "Weight: " << patient[I].weight << endl; cout << "Height: " << patient[I].height << endl; cout << "Age: " << patient[I].age << endl; cout << "BMR: " << patient[I].BMR << endl; cout << "Calories needed: " << patient[I].principle << endl; cout << "-------------------------------" << endl; } void fBMRcalc(Patient patient[],int I) { string System; switch(patient[I].system) { case 'M': case 'm': patient[I].BMR = 665.1 + (9.563 * patient[I].weight) + (1.850 * patient[I].height) - (4.676 * patient[I].age); break; case 'U': case 'u': patient[I].BMR = 655 + (4.35 * patient[I].weight) + (4.7 * patient[I].height) - (4.7 * patient[I].age); break; } switch(patient[I].active) { case 1: patient[I].principle = patient[I].BMR * 1.2; break; case 2: patient[I].principle = patient[I].BMR * 1.375; break; case 3: patient[I].principle = patient[I].BMR * 1.55; break; case 4: patient[I].principle = patient[I].BMR * 1.725; break; case 5: patient[I].principle = patient[I].BMR * 1.9; break; default: cout << "Invalid activity level!" << endl; break; } cout << "Patient's name was " << patient[I].FName << " " << patient[I].LName << endl; cout << "The system used was "; switch(patient[I].system) { case 'U': case 'u': System = "US system"; cout << System << endl; break; case 'M': case 'm': System = "Metric system"; cout << System << endl; break; default: System = "Invalid"; cout << System << endl; break; } cout << "Weight: " << patient[I].weight << endl; cout << "Height: " << patient[I].height << endl; cout << "Age: " << patient[I].age << endl; cout << "BMR: " << patient[I].BMR << endl; cout << "Calories needed: " << patient[I].principle << endl; cout << "------------------------" << endl; } int Display(Patient patient[],int I) { for(int i = 0;i < I;i++) { if(i == 1) { return 0; } switch(patient[i].gender) { case 'M': case 'm': mBMRcalc(&patient[i],i); break; case 'F': case 'f': fBMRcalc(&patient[i],i); break; default: cout << patient[i].FName << "'s gender was invalid!" << endl; break; } } } int main(int nNumberofArgs,char* pszArgs[]) { Patient patient[256]; char filename[256]; cout << "What data file would you like to analyze?" << endl; cout << "Filename: "; cin.getline(filename,256); for(int s = 0;s != '\n';s++) { if(filename[s] == NULL) { filename[s] = '.'; filename[s + 1] = 't'; filename[s + 2] = 'x'; filename[s + 3] = 't'; filename[s + 4] = NULL; break; } } cout << "Opening and reading contents of: " << filename << endl << endl << endl; ifstream File(filename); for(int s = 0;s < 256;s++) { double weight = 0.0,height = 0.0; int age = 0,active = 0; char system = 'n',gender = 'n'; char object[256] = ""; /* If metric, weight in kg and height in cm ** If US, weight in pounds and height in in */ File.getline(object,256); if(File.fail()) { cout << "End of file!" << endl; cout << "Processing..." << endl << endl << endl; for(int i = 0;i < s;i++) { Display(&patient[i],s); } return 0; } for(int i = 0;i < 256;i++) { patient[s].FName[i] = object[i]; } File.getline(object,256); for(int i = 0;i < 256;i++) { patient[s].LName[i] = object[i]; } File >> system; // 'M' = Metric, 'U' = US patient[s].system = system; File >> gender; // 'M' = Male, 'F' = Female patient[s].gender = gender; File >> age; patient[s].age = age; File >> weight; patient[s].weight = weight; File >> height; patient[s].height = height; File >> active; patient[s].active = active; File.getline(object,256); File.getline(object,256); for(int i = 0;i < 256;i++) { patient[s].Hash[i] = object[i]; } cout << "Data sets complete: " << s + 1 << endl; } } ``````