methods

I'm having trouble only reading in the value from my method. This program calculates the BMI of an athlete. I have 4 methods. 1 to get the height, 1 to get the weight, 1 to calculate the BMI, and 1 to print the BMI. The problem is, when I call the method to calculate the BMI it runs through the getHeight and getWeight methods weighting for another input for those variables, when I already put values into them.
Here is the code:
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
48
49
50
51
#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";
	BMI.printBMI();

	return 0;
}

BMI::BMI(void)
{
	weight = 0;
	height = 0;
	bmi = 0;
}

int BMI::getHeight() 
{	int height;
	cin.operator>>(height);	
	return height;}

int BMI::getWeight()
{	int weight;
	cin.operator>>(weight);
	return weight;}

int BMI::calculateBMI()
{	int bmi, h, w;
	h = getHeight();
	w = getWeight();
	bmi = w * (703/(h*h)); 
	return bmi;	}

void BMI::printBMI()
{	int bmi = calculateBMI();
	cout << "Please enter the Height in inches: ";
	getHeight();
	cout << "Please enter the Weight in pounds: ";
	getWeight();
	cout << "The BMI of the athlete is " << bmi << endl;	}


BMI::~BMI(void)
{
}
Last edited on
Topic archived. No new replies allowed.