I was trying a problem and wrote the following code. I have nested if else structures together. Is it correct? Is there any other way I can solve the problem? For example by using for or switch statements?
/*
Write a program which inputs a person’s height (in centimeters) and weight (in
kilograms) and outputs one of the messages: underweight, normal, or
overweight, using the criteria:
Underweight: weight < height/2.5
Normal: height/2.5 <= weight <= height/2.3
Overweight: height/2.3 < weight
*/
#include <iostream>
using namespace std;
int main()
{
float weight, underweight, normal, overweight;
int height;
cout << "Please enter your height in cm : " << endl;
cin >> height;
cout << "Please enter your weight in kg : " << endl;
cin >> weight;
if (weight<height/2.5)
cout << "Result : Underweight" << endl;
else if (height/2.5 <= weight <= height/2.3)
cout << "Result : Normal" << endl;
else if (height/2.3 < weight)
cout << "Result : Overweight" << endl;
return 0;
}