This is the result I get when I do that. The code just simply does not show up.
This is my updated code after doing what you told me to (not sure if correctly):
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
int main()
{
// Housekeeping
string name, result;
char c = 'y';
int counter = 0;
double BMI, height, weight, WEIGHTINLBS, HEIGHTININCHES, total_BMI = 0.0;
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: ";
getline(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 << endl;
cout << "Do you want add more entry? (Y or N): ";
cin >> c;
total_BMI = total_BMI + BMI; counter++;
}
cout << "The total BMI is " << total_BMI << endl; cout << "The number of people used is " << counter << endl;
double average_BMI = total_BMI / counter;
cout << "the average BMI is " << average_BMI;
system("cls");
system("type bmi.dat");
system("pause");
}