This C++ program calculates the number of chocolate bars a user can eat daily to maintain their weight based on their gender, weight, height, and age. It uses the Harris Benedict equation to determine basal metabolic rate and calculates the initial chocolate bar amount. It then allows the user to input their activity level to adjust the amount based on being sedentary, somewhat active, active, or highly active. The program loops to allow multiple users to calculate their results.
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
40 views
Example Cs
This C++ program calculates the number of chocolate bars a user can eat daily to maintain their weight based on their gender, weight, height, and age. It uses the Harris Benedict equation to determine basal metabolic rate and calculates the initial chocolate bar amount. It then allows the user to input their activity level to adjust the amount based on being sedentary, somewhat active, active, or highly active. The program loops to allow multiple users to calculate their results.
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2
// File Name: Homework number 13 page 109
// Author: Jimmy Yik
// Professor Jamal Ashraf /* Description: This program will determine how many chocolate bars you can eat in order to maintain your weight. * The user will input his/her gender, weight, height, and age to for the program to calculate BMR. Based on the calculated BMR, * the program will determine how many chocolate bars the use should eat based on Harris Benedict's equation. On top of this, * it also solves for an alternate amount of chocolate bars you need by including your frequency of execise. */ #include <iostream> #include <string> using namespace std; int main() { //Here are the listed variables. int pounds, height, age; double chocolate_bars, new_amaount; char ans, again, level_of_fitness; // Here I used do while to loop it in case user wants to do more calculations. do { cout << "Hi, to see how many chocolate bars please input the following." << endl; //I've set limits for each input to keep calculations within the realm of reality. cout << "Your weight in pounds.\n"; cin >> pounds; while (pounds < 0 || pounds > 1000) { cout << "Please give a feasible weight.\n"; cin >> pounds; } cout << "Your height in inches.\n"; cin >> height; while (height < 30 || height > 100) { cout << "Please give an actul human height.\n"; cin >> height; } cout << "Your age in years.\n"; cin >> age; while (age <=0 || age > 140) { cout << "Please provide your actual age.\n"; cin >> age; }
cout << "Type F or f for a female calculation while M or m for a male
calculation.\n"; cin >> ans; //There are two equations for both male and female. if (ans == 'F' || ans == 'f') { chocolate_bars = (655 + (4.3 * pounds) + (4.7 * height) - (4.7 * age)) / 230; } else { chocolate_bars = (66 + (6.3 * pounds) + (12.9 * height) - (6.8 * age)) / 230; } //The output of the equation is announced here. cout << "The number of chocolate bars you should eat is...\n"<< chocolate_bars<< endl; //This program is essentially the same one from an earlier problem, but it has the addon to fufill the extra requirements. cout << "HOWEVER. These calculations do not take execrise into account.\n"; cout << "If you'd like a more accurate calculation, please type 1 for sedentary, 2 for "; cout << " somewhat active 3 for Active or 4 for highly active.\n"; cin >> level_of_fitness; if (level_of_fitness == '1') { new_amaount = chocolate_bars * 1.2; } else if (level_of_fitness == '2') { new_amaount = chocolate_bars * 1.3; } else if (level_of_fitness == '3') { new_amaount = chocolate_bars * 1.4; } else if (level_of_fitness == '4') { new_amaount == chocolate_bars * 1.5; } cout << "Your actual amount would be "<< new_amaount<< " of chocolate bars.\n"; cout << "Type Y or y if you would like to do this again.\n"; cin >> again; } while (again == 'Y' || again == 'y'); return 0; }