You are on page 1of 2

#include "pch.

h"
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
{
float weight;
float height;
string Weight;

cout << "Please eneter your weight (Kg)" << "\n"; // this will ask the
user to input their weight in kilograms
cin >> weight; // user inputs their weight in kilograms

cout << "Please enter your height (m)" << "\n"; // this will ask the
user to input their height in meters
cin >> height; // user inputs their height in meters

int bmi = weight / (height * height); // this will calculate the users BMI

cout << "Your current BMI is" << "\n";


cout << bmi; // displays the BMI

cout << "\n\n";

if (bmi > 0 && bmi <= 15) { // if the BMI is between 0 to 15 it will
display the following message

cout << "You are seriously underweight" << "\n";


Weight = "You are seriously underweight";
}

else if (bmi > 16 && bmi <= 17) { // if the BMI is 16 / 17 it will dispay
the following message

cout << "You are underweight" << "\n";


Weight = "You are underweight";
}

else if (bmi > 18 && bmi <= 23) { // if the BMI is between 18 to 23 it will
dispay the following message

cout << "You are normal weight";


Weight = "You are normal weight";
}

else if (bmi > 24 && bmi <= 28) { // if the BMI is between 24 to 28 it will
dispay the following message

cout << "You are overweight";


Weight = "You are overweight";
}

else if (bmi > 29 && bmi <= 34) { // if the BMI is between 29 to 34 it will
dispay the following message
cout << "You are seriously overweight";
Weight = "You are seriously overweight";
}

else {

cout << "You are gravely overweight"; // if the BMI is over 34 it will
display this message
Weight = "You are gravely overweight";
}

ofstream MyWriteFile("filename2.txt"); //create the file

MyWriteFile << Weight; //write to file

MyWriteFile.close(); //close the file

string myText; //myText = Weight;

ifstream MyReadFile("filename2.txt");

while (getline(MyReadFile, myText)) {


cout << myText;
}

MyReadFile.close();

You might also like