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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "stdafx.h"
#include <iostream>
#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
1
2
3
4
5
6
BMI::BMI(void)
{
	weight;
	height;
	bmi;
}

supposed to be
1
2
3
4
5
6
BMI::BMI(void)
{
	int weight;
	int height;
	int bmi;
}
both are useless, no-effect statements
Topic archived. No new replies allowed.