Advertisement
Spocoman

Calorie Calculator

Sep 23rd, 2023
776
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     char gender;
  9.     cin >> gender;
  10.  
  11.     double weight, height, basalMetabolicRate, coefficientActivity;
  12.     cin >> weight >> height;
  13.  
  14.     int age;
  15.     cin >> age;
  16.     cin.ignore();
  17.  
  18.     string physicalActivity;
  19.     getline(cin, physicalActivity);
  20.  
  21.     if (gender == 'm') {
  22.         basalMetabolicRate = 66 + weight * 13.7 + height * 500 - 6.8 * age;
  23.     }
  24.     else {
  25.         basalMetabolicRate = 655 + weight * 9.6 + height * 180 - 4.7 * age;
  26.     }
  27.  
  28.     if (physicalActivity == "sedentary") {
  29.         coefficientActivity = 1.2;
  30.     }
  31.     else if (physicalActivity == "lightly active") {
  32.         coefficientActivity = 1.375;
  33.     }
  34.     else if (physicalActivity == "moderately active") {
  35.         coefficientActivity = 1.55;
  36.     }
  37.     else {
  38.         coefficientActivity = 1.725;
  39.     }
  40.  
  41.     int calories = ceil(basalMetabolicRate * coefficientActivity);
  42.  
  43.     printf("To maintain your current weight you will need %i calories per day.\n", calories);
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement