//BMI Calculator using user input
//Created by Ashish Mishra
//Oct 1st, 2011
#include<iostream>
#include<iomanip>
#include<math.h> // avoid cmath due to ambugious error
usingnamespace std;
int main()
{
unsignedint weight;
unsignedint height;
float bmi;
char response;
do
{
cout<<"*****************************\n";
cout<<"Please enter your weight (lbs): ";
cin>>weight;
cout<<"Please enter your height (inches): ";
cin>>height;
bmi = (weight/pow(height,2))*703;
cout<<"\n";
cout<<fixed<<showpoint<<setprecision(2);
cout<<"Your BMI is "<<bmi<<endl;
if (bmi < 18.5)
{ // braces used to illustrate use of compound statement.
cout<<"You are underweight!"<<endl;
cout<<"Eat more!!"<<endl;
}
elseif (bmi >= 18.5 && bmi <25)
cout<<"You are normal!"<<endl;
elseif (bmi >= 25 )
cout<<"You are overweight!"<<endl;
else
cin.get();
cin.get();
cout<<endl;
cout<<"Would you like to enter the information again? ";
cin>>response;
}
while (response == 'Y' || 'y' );
return 0;
}
while one of the following two things is true -
1) response equals 'Y'
2) 'y'
Note that point two is not "response equals 'y' "
So, sometimes point one will come up as true, sometimes it will be false.
Point 2 will always, always be true. 'y' is not zero, and thus is true. Always.
I suspect you meant this to be
while one of the following two things is true -
1) response equals 'Y'
2) response equals 'y'