Hi. I received errors such as float bmi is a private members. How can I access the private members in the main? Thanks in advance.
Code:
#include <iostream>
using namespace std;
class BMI
{
private:
float height, weight, bmi;
public:
BMI()
{
height = 1.0;
weight = 1.0;
}
void set(float a, float b)
{
height = a;
weight = b;
}
void calculate()
{
bmi = ((weight / 1000) / (height * height));
}
void display()
{
string status;
if (bmi < 18.5)
{
status = "Underweight";
}
else if (bmi > 18.5 && bmi < 24.9)
{
status = "Normal";
}
else if (bmi > 25 && bmi < 29.9)
{
status = "Overweight";
}
else
{
status = "Obese";
}
cout << status;
}
};
int main()
{
BMI c;
cout << "This program will calculate your body mass index." << endl;
cout << "Enter your height in meter (m) unit : ";
cin >> c.height;
cout << "Enter your weight in kilogram (kg) unit : ";
cin >> c.weight;
cout << "Your bmi is : " << c.bmi << endl;
c.display();
return 0;
}
Output that needs to display:
This program will calculate your body mass index.Enter your height in meter (m) unit : 1.63Enter your weight in kilogram (kg) unit : 45Your bmi is : 16.937You are underweight.