// Alicia Thorsen // caloric_intake_calculator_functions.C // 2/1/08 // // Calculates the daily recommended number of calories a person should // consume to lose weight. Can also be used for weight maintenance and // weight gain. #include using namespace std; // # of calories in a lb const int CAL_IN_A_LB = 3500; void getUserInfo(double&, double&, char&, int&, int&, int&, double&); double calculateBMI(double, double); double sedentaryLifestyleNeeds(char, double, double, int); void recommendedCaloricIntake(double, int, int, double); int main() { double weight = 0, height = 0, bmi = 0, sedentaryNeeds = 0, lbsToLose = 0; int age = 0, cardioDays = 0, cardioCal = 0; char sex, quit = 'n'; system("clear"); cout << "\nWelcome to the Daily Caloric Intake Calculator!"; cout << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"; cout << "\nTo get started, we need some basic information."; do { // Get personal information from user getUserInfo(weight, height, sex, age, cardioDays, cardioCal, lbsToLose); // Calculate body mass index bmi = calculateBMI(weight, height); // Calculate # of calories required for a sedentary lifestyle sedentaryNeeds = sedentaryLifestyleNeeds(sex, weight, height, age); // Calculate recommended daily caloric intake recommendedCaloricIntake(sedentaryNeeds, cardioDays, cardioCal, lbsToLose); cout << "\nWould you like to quit? (y/n) : "; cin >> quit; } while (quit != 'y'); cout << endl; return 0; } void getUserInfo(double& weight, double& height, char& sex, int& age, int& cardioDays, int& cardioCal, double& lbsToLose) { int heightFt = 0, heightIn = 0; char temp; // Get user personal data cout << "\n\nWeight in lbs: "; cin >> weight; cout << "Height (e.g. 5'7\"): "; cin >> heightFt >> temp >> heightIn >> temp; cout << "Sex (m/f): "; cin >> sex; cout << "Age: "; cin >> age; cout << "# of days of cardio workout per week: "; cin >> cardioDays; cout << "# of calories burned per cardio workout: "; cin >> cardioCal; cout << "# of lbs to lose per week : "; cin >> lbsToLose; // Convert weight to kg and height to m weight /= 2.2; height = ((heightFt * 12) + heightIn) * 0.0254; } double calculateBMI(double weight, double height) { double bmi = 0, weightLowerEnd = 0, weightUpperEnd = 0; // Calculate BMI bmi = weight / (height * height); // Output BMI and category cout.setf(ios::fixed | ios::showpoint); cout.precision(1); cout << "\nYour BMI is " << bmi << ".\n"; cout << "Based on your BMI, "; if (bmi < 18.5) cout << "you are underweight."; else if (bmi < 25) cout << "your weight is normal."; else if (bmi < 30) cout << "you are overweight."; else cout << "you are obese."; weightLowerEnd = 18.6 * height * height * 2.2; weightUpperEnd = 24.9 * height * height * 2.2; // Output recommended weight ranges cout << "\nYour recommended weight range is " << static_cast(weightLowerEnd) << " to " << static_cast(weightUpperEnd) << endl; return bmi; } double sedentaryLifestyleNeeds(char sex, double weight, double height, int age) { double bmr = 0; // Basal Metabolic Rate (BMR) if (sex == 'm') bmr = 66 + (13.7 * weight) + (5 * height * 100) - (6.8 * age); else bmr = 655 + (9.6 * weight) + (1.8 * height * 100) - (4.7 * age); // Sedentary lifestyle needs return (bmr * 1.2); } void recommendedCaloricIntake(double sedentaryNeeds, int cardioDays, int cardioCal, double lbsToLose) { double dailyCalBurned = 0, calIntake; int calUpperEnd = 0, calLowerEnd = 0; // Calories burned daily from bodily functions & exercise dailyCalBurned = sedentaryNeeds + ((cardioDays * cardioCal) / 7); // Recommended caloric intake for desired weight loss calIntake = dailyCalBurned - ((CAL_IN_A_LB * lbsToLose) / 7); calLowerEnd = static_cast(calIntake) - 250; calUpperEnd = static_cast(calIntake) + 100; cout << "\nRecommended Daily Caloric Intake is " << calLowerEnd << " to " << calUpperEnd << ".\n"; }