make a c++ program that will calculate body mass index using if-else condition.
#include <iostream>
using namespace std;
int main() {
double index, weight, weightInKilograms, height;
double heightInMeters, heightSquared, kilogramsPerPound, metersPerInch;
// initialize constants and variables
kilogramsPerPound = 0.45359237;
metersPerInch = 0.0254;
// get user input values
cout<<"Enter weight = ";
cin>> weight;
cout<<"Enter height = ";
cin>> height;
// perform calculations
heightInMeters=height*metersPerInch;
weightInKilograms=weight*kilogramsPerPound ;
heightSquared= heightInMeters*heightInMeters;
index = weightInKilograms/heightSquared;
cout<<"index = "<<index<<endl;
// decide index category
if(index<18.5)
cout<<"You are underweight";
else if(index<25.0)
cout<<"Your weight is normal";
else if(index<30.0)
cout<<"Your weight is overweight";
else
cout<<"Your weight is obese";
cout<<endl<<endl;
system("PAUSE");
return 0;
}
Comments
Leave a comment