I need to format my BMR output so it has a nice neat appearance with the Headings over each column. In one column it should say BMR and the other Daily Calorie Intake. This is what I have so far:
/* Program: Harris Benedict Equation
*
*/
# 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 wgt, hgt, age, act_lvl;
char sex;
int bmr, calories;
data.open ("bmr_inputs.txt"); //file for input
if (!data)
{
cout << "Error!!! Failure to Open bmr_inputs.txt" << endl;
system ("pause");
return 1;
}
out.open ("out.txt"); //file for output
if (!out)
{
cout << "Error!!! Failure to Open out.txt" << endl;
system ("pause");
return 1;
}
Get_Data (data,wgt, hgt, age, sex, act_lvl);
while (data)
{
bmr = Basal_Meta_Rate (wgt, hgt, age, sex);
calories = Caloric_Needs (bmr, act_lvl);
out<< "bmr " << bmr << " calories " << calories <<endl;
Get_Data (data,wgt, hgt, age, sex, act_lvl);
}
cout << "The End..." <<endl;
data.close ();
out.close ();
system ("pause");
return 0;
} //main
void Get_Data (ifstream& data, int& wgt, int& hgt, int& age, char& sex, int& act_lvl)
{
data>> wgt;
data>> hgt >> age >> sex >> act_lvl;
}
int Basal_Meta_Rate (int wgt, int hgt, int age, char sex)
{
if (sex == 'M')
{
return (66 + (6.23 * wgt) + (12.7 * hgt) - (6.76 * age));
}
else
{
return (655 + (4.35 * wgt) + (4.7 * hgt) - (4.7 * age));
}
}
int Caloric_Needs (int bmr, int act_lvl)
{
int calories;
if (act_lvl == 1)
{
calories = (bmr * 1.2);
}
else if (act_lvl == 2)
{
calories = (bmr * 1.375);
}
else if (act_lvl == 3)
{
calories = (bmr * 1.55);
}
else if (act_lvl == 4)
{
calories = (bmr * 1.725);
}
else if (act_lvl == 5)
{
calories = (bmr * 1.9);
}
return (calories);
}
I have attched my input file as well. Thanks so much!!!