#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
// Coded by Gabriel Lanctot
// The purpose of this assignment is to calculates the BMI of a person once the information has been received from the user.
// Known issues: Program running twice. Doesnt make a text file
int main()
{
// Housekeeping
string name, result;
char c='y';
double BMI, height, weight, WEIGHTINLBS, HEIGHTININCHES;
const double LB2KG = 0.45359237, INCH2METRE = 0.0254;
cout << fixed << setprecision(1);
ofstream fout("bmi.dat");
fout << fixed << setprecision(1);
if (!fout.is_open())
{
cout << "error opening file ";
return 0;
}
// Input
fout << setw(10) << " Body Mass Index Report " << endl;
fout << left << setw(20) << "Name" << setw(20) << "Weight" << setw(20) << "Height" << setw(20) << "BMI" << setw(20) << "Result" << endl << endl;
while(c=='y'||c=='Y')
{
system("cls");
cout << "Enter your name: ";
cin >> name;
cout << "Enter weight(lbs): ";
cin >> weight;
cout << "Enter height(inches): ";
cin >> height;
// Processing
WEIGHTINLBS = weight * LB2KG;
HEIGHTININCHES = height * INCH2METRE;
BMI = WEIGHTINLBS / (HEIGHTININCHES * HEIGHTININCHES);
if (BMI < 18.5)
{
result= "Under weight";
}
else if (BMI > 24.9)
{
result= "Over weight";
}
else
{
result= "Normal weight";
}
// Output
fout << left << setw(20) << name << left << setw(20) << weight << setw(20) << height << setw(20) << BMI << setw(20) << result << endl;
cout<<"Do you want add more entry? (Y or N): ";
cin>>c;
}
system("cls");
system("type bmi.dat");
system("pause");
}