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:
#include "stdafx.h"
#include <iostream>
#include "BMI.h"
usingnamespace 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)
{
}