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
|
//programmer: Nico Agtuca
//instructor: Robert Sterling
//program name: BMR Calculator
# include <fstream>
# include <iostream>
# include <iomanip>
using namespace std;
//prototypes
void Get_Data (ifstream&, int&, int&, int&, char&, int&); // Reads in data from file
int Basal_Meta_Rate (int, int, int, char); // Weight, Height, Age, and Sex
int Caloric_Needs (int, int); // BMR and Activity Level
int main ()
{
ifstream data;
ofstream out;
int weight, height, age, activity_level;
char sex;
int bmr, calories;
data.open ("Program2Input.txt"); //file for input
Get_Data (data,weight, height, age, sex, activity_level);
while (data)
{
bmr = Basal_Meta_Rate (weight, height, age, sex);
calories = Caloric_Needs (bmr, activity_level);
cout << "Weight\tHeight\tAge\tSex\tActivity Level\tBMR\tTotal Calories" << endl;
cout << "------\t------\t---\t---\t--------------\t----\t--------------" << endl;
cout << setw(4)<< weight << setw(8)<< height << setw(7) << age
<< setw(7) << sex << setw(14) << activity_level
<< setw(12)<< bmr << setw(13)
<< calories << endl << endl;
Get_Data (data,weight, height, age, sex, activity_level);
}
cout << "Press enter twice to exit the program" <<endl;
cin.ignore();
cin.get();
data.close ();
out.close ();
return 0;
}
//main
void Get_Data (ifstream& data, int& weight, int& height, int& age, char& sex, int& activity_level)
{
data>> weight;
data>> height >> age >> sex >> activity_level;
}
int Basal_Meta_Rate (int weight, int height, int age, char sex)
{
if (sex == 'M')
{
return (66 + (6.23 * weight) + (12.7 * height) - (6.76 * age));
}
else
{
return (655 + (4.35 * weight) + (4.7 * height) - (4.7 * age));
}
}
//calories
int Caloric_Needs (int bmr, int activity_level)
{
double calories;
if (activity_level == 1)
{
calories = (bmr * 1.2);
}
else if (activity_level == 2)
{
calories = (bmr * 1.375);
}
else if (activity_level == 3)
{
calories = (bmr * 1.55);
}
else if (activity_level == 4)
{
calories = (bmr * 1.725);
}
else if (activity_level == 5)
{
calories = (bmr * 1.9);
}
return (calories);
}
|