0

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;

    cout << "\nPlease enter your height in inches." <<endl << endl;
    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;

}

Edited by Reverend Jim: Fixed formatting

3
Contributors
12
Replies
13
Views
7 Years
Discussion Span
Last Post by jonsca
0

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;

cout << "\nPlease enter your height in inches." <<endl << endl;
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;

}

Edited by mike_2000_17: Fixed formatting

0

Your problem is that your are eventually doing :

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

0

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

Edited by skarocks47: n/a

0

>>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?

0

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.

0

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.

0

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?

0

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?

0

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

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.