### result is always 0

This program is supposed to return the BMI of an athlete. As I go through it, it gets to the calculation part and it's storing the values for height and weight properly, but it won't store the result of the equation for the BMI. It keeps giving me 0. Does anyone know what's wrong? Any help would be appreciated.
 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647`` ``````#include "stdafx.h" #include #include "BMI.h" using namespace std; int main() { BMI BMI; cout << "This program will calculate the BMI of an athlete.\n"; cout << "Please enter the Height in inches: "; BMI.getHeight(); cout << "Please enter the Weight in pounds: "; BMI.getWeight(); BMI.printBMI(); return 0; } BMI::BMI(void) { weight; height; bmi; } int BMI::getHeight() { cin.operator>>(height); return height;} int BMI::getWeight() { cin.operator>>(weight); return weight;} int BMI::calculateBMI(int height, int weight) { int ans; ans = (weight * (703/(height*height))); return ans; } void BMI::printBMI() { int result = calculateBMI(height, weight); cout << "The BMI of the athlete is " << result << endl;} BMI::~BMI(void) { } ``````
I think that the problem is in the statement

ans = (weight * (703/(height*height)));

It seems that height and weight are declared as integer numbers. In this case the result of expression 703/(height*height) is always equal to 0 if 703 is less that height * height.
Last edited on
integers are not as accurate as floating points since a < b then a/b = 0 for all a and b because yor divisor is greater than your dividend (numerator). it rounds down.
integers are actually more accurate ;P They're not subject to rounding and precision issues like floating points are.

They're just don't allow for floating points.

</hypertechnicality>
^lol i generally meant that. Hypertechnical one.
isnt
 ``123456`` ``````BMI::BMI(void) { weight; height; bmi; }``````

supposed to be
 ``123456`` ``````BMI::BMI(void) { int weight; int height; int bmi; }``````
both are useless, no-effect statements
Topic archived. No new replies allowed.