So i am just starting out learning C ++ and i was trying to make a BMI calculator. When ever i run the program and it prints the BMI number its a weird number. Not one it should get. Please can u help me out with my source?

``````#include <iostream>
using namespace std;

int main(void)

{
int myweight;
int myheight;
int mynum;
mynum = 703;
int mybmi;
int squared;

cout << "Please enter your weight in pounds." << endl << endl;
cin >> myweight;

cin >> myheight;
cin.ignore();

squared = (myheight * myheight);
mybmi = ((myweight * mynum)/squared);

if (mybmi < 18.5) {
cout << "\nYour BMI is:" << mybmi << cout << "\tYour BMI says you are Underwight." << endl;
}
else if (mybmi >= 18.5) {
cout << "\nYour BMI is:" << mybmi << cout << "\tYour BMI says you are Normal." << endl;
}
else if (mybmi >= 25){
cout << "\nYour BMI is:" << mybmi << cout << "\tYour BMI says you are Overwight." << endl;
}
else if (mybmi >= 30){
cout << "\nYour BMI is:" << mybmi << cout << "\tYour BMI says you are Obese." << endl;
}

cin.get();

system("pause");

return 0;

}
``````

## All 12 Replies

First use code tags when posting code so we can read it better(its the button on the tool list that says "(code)" ).

here is your code with code tags

``````#include <iostream>
using namespace std;

int main(void)

{
int myweight;
int myheight;
int mynum;
mynum = 703;
int mybmi;
int squared;

cout << "Please enter your weight in pounds." << endl << endl;
cin >> myweight;

cin >> myheight;
cin.ignore();

squared = (myheight * myheight);
mybmi = ((myweight * mynum)/squared);

if (mybmi < 18.5) {
cout << "\nYour BMI is:" << mybmi << cout << "\tYour BMI says you are Underwight." << endl;
}
else if (mybmi >= 18.5) {
cout << "\nYour BMI is:" << mybmi << cout << "\tYour BMI says you are Normal." << endl;
}
else if (mybmi >= 25){
cout << "\nYour BMI is:" << mybmi << cout << "\tYour BMI says you are Overwight." << endl;
}
else if (mybmi >= 30){
cout << "\nYour BMI is:" << mybmi << cout << "\tYour BMI says you are Obese." << endl;
}

cin.get();

system("pause");

return 0;

}
``````

ok thank you.. im new to this.

``cout<<cout;``

which is print the object's address.

For example :

``````if (mybmi < 18.5) {
cout << "\nYour BMI is:" << mybmi << cout << "\tYour BMI says you are Underwight." << endl;
}``````

Break it up to this :

``````if (mybmi < 18.5) {
cout << "\nYour BMI is:" << mybmi <<endl;
cout << "\tYour BMI says you are Underwight." << endl;
}``````

Do this for others as well

Thank you so much. Now I have another problem. The only 2 messages it wants to print: the underweight and normal one.
Is it possible to do a range for these?

``else if (mybmi >= 25``

>>Thank you so much. Now I have another problem. The only 2 messages it wants to print: the underweight and normal one.
Is it possible to do a range for these?

What do you mean? You only want the underweight and normal to be
a option?

I mean that only the only things that are printing are the normal and underweight one. So if the BMI is less than 18.5 it says underwight. Any number above that says the normal print out. So lets say for example the BMI is 30 and that supposed to print out the Obese text. but it prints out the normal one.

Oh right, its your conditional expression thats giving you problems :

``````if (mybmi < 18.5) {
}
else if (mybmi >= 18.5 && mybmi <25) {
}
else if (mybmi >= 25 && mybmi < 30){
}
else if (mybmi >= 30){
}``````

Basically this part of the code for example :

``else if (mybmi >= 25 && mybmi < 30)``

reads as : " if my body mass index is greater than 25 but less than 30 then i am over weight" for this situation.

The "&&" is called "and" operator. Google its truth table and its further uses.

Thanks it worked.

One last question. I built it and compiled it. When i try to run the exe on another computer it doesnt want to. What gives?

One last question. I built it and compiled it. When i try to run the exe on another computer it doesnt want to. What gives?

what do you mean "it doesn't want to"? Does it give some errors?

It gives me an error. The error is "This application has failed to start because the application configuration is incorrect. Please try reinstalling the application."

I didnt install anything in the first place

Are you using Visual C++? If so, did you try to run a debug build on the other machine? If so, you need the release build.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.