The C++ code is pasted below.
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
float bmi;
ifstream inFile;
inFile.open("bmi.txt");
while (!inFile.eof())
{
inFile >> bmi;
if( bmi < 18.5)
{
cout << bmi << " is underweight " ;
}
else if( bmi >= 18.5 && bmi <= 24.9)
{
cout << bmi << " is in normal range " ;
}
else if( bmi >= 25.0 && bmi <= 29.9)
{
cout << bmi << " is overweight " ;
}
else if( bmi >= 30)
{
cout << bmi << " is obese " ;
}
cout << endl;
}
return 0;
}
Sample Input Text File - bmi.txt
Output Screen
Get Answers For Free
Most questions answered within 1 hours.