Hello ThatGrayRock,
Sorry I got into something after dinner and did not get back to this.
Computer Not Following Formula Right |
Actually it is. It is your code that is not quite right.
Lines 26 - 32, with the exception of line 31, is going about what you want in the wrong way.
Given your output of:
Month # Monthly Payment Total Paid Remaining Balance
1 $165.25 $165.25 $969.82
2 $165.25 $330.50 $5620.71 |
What do you expect to see for these numbers? And should I consider the interest as being part of the $165.25 amount?
I would make this change at the start of the program:
1 2
|
double Balance = 5784.73;
double RemainingBalance = Balance;
|
Changing the order does not make any difference right now, but a more logical way of doing these lines. In the future it should make a difference.
Try changing to this code. I think you will see that it is not what you want.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
//std::cout << "Month #\tMonthly Payment\tTotal Paid\tRemaining Balance" << std::endl;
std::cout << "Month #\tMonthly Payment\t\tInterest\tTotal Paid\tRemaining Balance" << std::endl;
for (int LCVColumns = 1; LCVColumns <= MaxColumns; LCVColumns++)
{
for (int LCVRows = 1; LCVRows <= MaxRows; LCVRows++)
{
const double MonthlyInterestRate = 0.0075;
Month = Month + 1;
double test = ((1 - (pow(1 + MonthlyInterestRate, (PaymentsToBeMade - TotalPayments)))) / MonthlyInterestRate);
Payments = MonthlyPayment * test;
PaymentsToBeMade = TotalPayments - Month;
PaidSoFar = Month * MonthlyPayment;
RemainingBalance = Balance - Payments;
std::cout << std::fixed << std::setprecision(2);
std::cout << Month << "\t$" << MonthlyPayment << "\t\t\t" << Payments << "\t\t$" << PaidSoFar << "\t\t$" << RemainingBalance << std::endl;
//std::cout << Month << "\t$" << MonthlyPayment << "\t\t$" << PaidSoFar << "\t\t$" << RemainingBalance << std::endl;
}
}
|
I put the big formula on a line by its-self so you can stop the program and see what its value is for any given line. The changes I made are for testing and do not have to stay in the final program.
On line 10 when you calculate the value of "Payments" I do not think that is a number that you want. On the first run through the for loops "Payments" has a value of 5195.58. I do not think that is what you wanted. Part of the formula "(PaymentsToBeMade - TotalPayments)" the first time through the loops this has a value of -36 and "test" has a value of 31.45. Is the value of test what you expected?
In my above code line 8 does not need to be here. What you can do when you first define "MonthlyInterestRate" make it a "const".
I also have to question the use of "pow()". I do not follow the need or use of this. I believe all you need to do is multiply the "RemainingBalance" by the "MonthlyInterestRate" to get the interest for the month. Still something I have to work on.
Do you have any sample output that is correct? It is a big help to figure out what is going wrong.
Hope that helps,
Andy