returning a value of an array function

I am stuck and don't know where to go from here.
I have to take the 4 calculated values of a calcMonPayment function and implement it in a print out function DisplayLoanSchedule .
All the print out function prints however,is the last calculated value of the calculating function. I don't know how I can have all 4 array values sent to printing function in order for it to print out correctly.

It should be printed out as:
24 month $490.00
36 month $339.00
48 month $263.00
60 month $218.00

All I am getting is:
24 month $218.00
36 month $218.00
48 month $218.00
60 month $218.00

Hope somene can help me . Thanks
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
//*******************************************************************************
void DisplayLoanSchedule(int& noMonths, float monPayment)
 {
   noMonths = 24;
   int index;
    for (index = 0; index <= 3; index++)
    {
        cout << noMonths << " Months" << fixed << setprecision(2) << setw(20) << monPayment << endl;
        noMonths = noMonths + 12;
    }
 
   return;
 } 


//*******************************************************************************
float calcMonPayment(float& annualIntRate,float& loanAmt, float& monIntRate, float& monPayment)
{
	int noMonths[4]={24,36,48,60};
	int index;

	monIntRate =  annualIntRate  / 12.0;
	cout <<"monthly Intrest rate: " << fixed << setprecision(5) << monIntRate << endl;
	for(index=0; index <4; index++)
	{
	monPayment = (loanAmt * monIntRate)/(1.0-pow((monIntRate+1), -noMonths[index]));
	cout << "Monthly payments are :" << fixed << setprecision(2) << monPayment << endl;
	}
	return monPayment;
}
//******************************************************************************* 
Last edited on
1
2
3
4
5
6
    for (index = 0; index <= 3; index++)
    {
        cout << noMonths << " Months" << fixed << setprecision(2) << setw(20) << monPayment << endl;
        noMonths = noMonths + 12;
    }
 


you never modify monPayment in this loop so it will consistnely print out the current value of monPayment

I am sorry to ask. But how would I modify the nonPayment??
Figured it out after studying the book again and reevaluating the problem. Thank you
Last edited on
Topic archived. No new replies allowed.