Code:
//bP.h
const int SYSTOLIC_LIMIT = 140;
const int DIASTOLIC_LIMIT = 90;
class BP
{
public:
//BP();
void GetPressure();
void Average();
bool Test();
void ReportResult(bool result_par);
void RunTest();
private:
int firstDiastolic, secondDiastolic, thirdDiastolic;
int firstSystolic, secondSystolic, thirdSystolic;
double sysAvg, diaAvg;
bool result;
};
Code:
//bP.cpp
#include "bP.h"
#include <iostream>
using namespace std;
//------------------------------------------------------------------------------
void BP::GetPressure()
{
cout << "Please enter your Diastolic Pressure readings: ";
cin >> firstDiastolic >> secondDiastolic >> thirdDiastolic;
cout << "\nPlease enter your Systolic Pressure readings: ";
cin >> firstSystolic >> secondSystolic >> thirdSystolic;
cout << "Diastolic Pressure Readings: " << firstDiastolic << " " << secondDiastolic << " " << thirdDiastolic << endl;
cout << "Systolic Pressure REadings: " << firstSystolic << " " << secondSystolic << " " << thirdSystolic << endl;
}
//--------------------------------------------------------------------------------
void BP::Average()
{
diaAvg = (firstDiastolic + secondDiastolic + thirdDiastolic) / 3;
sysAvg = (firstSystolic + secondSystolic + thirdSystolic) / 3;
cout << "Your average Diastolic Pressure is: " << diaAvg << endl;
cout << "Your average Systolic Pressure is: " << sysAvg << endl;
}
//--------------------------------------------------------------------------------
bool BP::Test()
{
//result = false;
if ( diaAvg > DIASTOLIC_LIMIT || sysAvg > SYSTOLIC_LIMIT )
result = true;
return result; //[result is filled with a value at this point]
}
//--------------------------------------------------------------------------------
void BP::ReportResult(bool result_par)
{
if ( result_par == true )
cout << "Your blood pressure is too high, you should see your doctor!\n";
else
cout << "Your blood pressure is not too high, congratulations! I recommend you get rechecked in 6 months.\n";
}
void BP::RunTest()
{
}
Code:
//runBP.cpp
#include "bP.h"
int main()
{
bool result = false;
BP test;
test.GetPressure();
test.Average();
test.Test();
test.ReportResult(result); /*[this is where I am having my disconnect, result empties out to 0 at this point and I don't know why]*/
return 0;
}
Can anyone shed some light as to why test.ReportResult(result) sends in an empty value? I have monitored the value step by step and if the averages are above the limits I set then result == true, but when result is returned to main the value resets to zero. Can anyone inform me on what I am doing incorrectly? Thanks