Amortization Table

Hi, I feel like I'm missing something very elementary but my brain's not functioning properly. I've got this table due tomorrow but not quite sure where I'm going wrong. I'm certain it's something to do with the loop but can't quite figure it out.

Here's my code:

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "math.h"
#include <iostream>
#include <iomanip>
using namespace std;
        double mirFunction(double num);
        int main()
        {
           int loanAmount = 70000; //amount of the loan
           double interestRate = 9.5;
           int years =  30; //years of the loan
           int loanMonths = years * 12; //loan term in months
           double mPayment; //variable for ouputting the payment
           double monthlyInterestRate; //variable for Monthly Interest Rate

         monthlyInterestRate = (interestRate / 1200); //mir = yir/1200
        cout << "Monthly Interest Rate:  $" << setprecision(4) << monthlyInterestRate << endl;
         double a = (monthlyInterestRate + 1);
        cout << "Variable A: " << setprecision(6) << (a) << endl;
         double b = (1 / a);
        cout << "Variable B: " << setprecision(6) << (b) << endl;
         double c = (loanMonths);
        cout << "Variable C: " << setprecision(6) << (c) << endl;
         double d = pow(b, c);
        cout << "Variable D: " << setprecision(6) << (d) << endl;
         double e = (1-d);
        cout << "Variable E: " << setprecision(6) << (e) << endl;
         double monthlyInterest  = (loanAmount * monthlyInterestRate);
        cout << "Monthly Interest: " << setprecision(6) << (monthlyInterest) << endl;
         double payment = (monthlyInterest/e);
        cout << "Principle: " << (loanAmount) << "     ";
        cout << "Interest Rate: " << (interestRate) << "     ";
        cout << "Years: " << (years) << "     ";
        cout << "Payment: " << setprecision(5) << (payment) << "     ";
        cout << "Monthly Interest Rate: " << setprecision(5) << (mirFunction(9.5)) << endl;

        double  totalPaid;
        double principalPaid;
        double remainingBalance;
        double totalPrincipalPaid;
        for(int i =0; i < 10; i++)
        {

                totalPaid = payment * i;
                principalPaid = totalPaid - monthlyInterest;
                totalPrincipalPaid += principalPaid;
                remainingBalance = 70,000 - totalPrincipalPaid;
                cout << setw(15) << setprecision(2) << fixed << "     Month: " << i;
                cout << setw(15) << setprecision(2) << fixed << "     Total Paid: " << totalPaid;
                cout << setw(15) << setprecision(2) << fixed << "     Principal Paid: " << principalPaid;
                cout << setw(15) << setprecision(2) << fixed << "     Total Principal Paid: " << totalPrincipalPaid;
                cout << setw(15) << setprecision(2) << fixed << "     Remaining Balance: " << remainingBalance << endl;
        }

        return 0;
}

double mirFunction(double num)
{
        double result;
        result = (num / 1200);
        return result;
}


Pastie link of my code if you prefer: http://pastie.org/private/y0v2eblo62mpx3hvnsvyhw

Here's a picture of the output: http://i.imgur.com/sC79o.jpg
Here's a picture of the expected output: http://i.imgur.com/dohP9.jpg

I'm just testing my program for the first 10 months before I modify it to to the full 360 months (30 years), but the numbers are still nowehre near what is expected. Can anyone help me?
Topic archived. No new replies allowed.