Answer to Question #338259 in C++ for fiona

Question #338259

make a c++ program that will calculate body mass index using if-else condition.


1
Expert's answer
2022-05-06T15:34:53-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS