I am writing a program for a class I am taking. I am having problems getting the proper output. I have programmed many times before and usually I would make my method declarations global. However our professor told us that we are not allowed to have global functions. All of our functions must be declared in the Main loop. Below is the loop that calls on the two primary functions. The first one runs a calculation. The other one displays the output to the screen. The problem is that the program is not doing the calculation multiple times but instead outputs the same number multiple times. Any help is greatly appreciated.
The loop:
for ( YearNumber = 1; YearNumber <= Years; YearNumber++)
{
/*--------------------------------------------------*/
/* */
/* Call ComputeFutureValue Function */
/* */
/*--------------------------------------------------*/
ComputeFutureValue (Principle, OnePlusInterestRate, YearNumber);
/*--------------------------------------------------*/
/* */
/* Call DisplayYearInfo Function */
/* */
/*--------------------------------------------------*/
DisplayYearInfo (YearNumber, FutureValue);
}
The Compute Function:
float ComputeFutureValue (float Principle, float OnePlusInterestRate, int YearNumber)
{
float FutureValue = Principle * pow (OnePlusInterestRate, YearNumber);
}
The display method:
void DisplayYearInfo (int YearNumber, float FutureValue)
{
cout << setw (2)
<< YearNumber
<< setw (22)
<< FutureValue
<< "\n";
}
your
ComputeFutureValuedoesn’t return anything – it only declares a local variable that won’t be visible outside of the function.