The calculator works perfectly fine but sometimes (mostly when the result is overweight) it displays 2 outputs i.e normal AND overweight whereas it should only display overweight.
#include <iostream>
usingnamespace std;
int main()
{
float a,b,c,d,e,f,g
;cout<<"Enter your weight in kilograms\n";
cin>>a;
cout<<"Enter your height in feet\n";
cin>>b;
cout<<"Enter your height in inches\n";
cin>>c;
d= b*12;
e= (d+c)*2.54;
f=e/100
;g= a / (f*f)
;cout<<"Your BMI is=\n";
cout<<g;
if (g<=18.5);
cout<<"\tYou are Underweight\n";
if (g>18.5 && g<25)
;cout<<"\tYou are normal\n";
if (g>=26)
;cout<<"\tYou are overweight\n";
return 0;
}
#include <iostream>
usingnamespace std;
int main()
{
float a,b,c,d,e,f,g
;cout<<"Enter your weight in kilograms\n";
cin>>a;
cout<<"Enter your height in feet\n";
cin>>b;
cout<<"Enter your height in inches\n";
cin>>c;
d= b*12;
e= (d+c)*2.54;
f=e/100
;g= a / (f*f)
;cout<<"Your BMI is=\n";
cout<<g;
if (g<=18.5)
cout<<"\tYou are Underweight\n";
elseif (g>18.5 && g<25)
cout<<"\tYou are normal\n";
elseif (g>=26)
cout<<"\tYou are overweight\n";
return 0;
The only thing I could suggest is to check that you are definitely compiling & running the code that you posted. The following code (that you posted) should work perfectly no-matter what compiler you use:
#include <iostream>
usingnamespace std;
int main()
{
float a,b,c,d,e,f,g
;cout<<"Enter your weight in kilograms\n";
cin>>a;
cout<<"Enter your height in feet\n";
cin>>b;
cout<<"Enter your height in inches\n";
cin>>c;
d= b*12;
e= (d+c)*2.54;
f=e/100
;g= a / (f*f)
;cout<<"Your BMI is=\n";
cout<<g;
if (g<=18.5)
cout<<"\tYou are Underweight\n";
elseif (g>18.5 && g<25)
cout<<"\tYou are normal\n";
elseif (g>=25)
cout<<"\tYou are overweight\n";
return 0;
}
I have many painful memories of pulling my hair out when my code won't work, only to find that I am editing the wrong file, or the compilation was failing & I was running an old executable. Maybe it's something like that?