Amortization chart problem

Hi everyone. My assignment is to do an Amortization chart for an inital balance of 350K, a 5.5% interest rate and 500 dollars added additionaly to the montlypayment which is to be applied to the principal balance. this is loan 3 of a 3 part loan assignment. I finished the other ones already but this one is giving me trouble. I did this in codepad. i couldnt think of any variables so i just chose random ones. I'll highlight where codepad says i have an error. where i highlighted, codepad said that the area above it is an error. i dont even think the output is going to be right because when i did it with just the 5.5 interest rate my output came out as negative numbers. see?
http://codepad.org/8Co6jtOb

anyway. thanks for the help!



#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main()
{
double loan, rate, moInterestRate, years, balance, term, payment;
double monthlyPayment = 500;
int numPayments;

years = 30;
loan = 350000;
rate = .055;


cout << "Loan amount: $350000\n";
cout << "Annual interest rate (entered as a decimal): 5.5\n";
cout << "Years of loan: 30\n";

numPayments = static_cast<int>(12 * years);
moInterestRate = rate / 12.0;
if (rate == 0)
payment = loan / numPayments;
else
{ term = pow((1 + moInterestRate), numPayments);
payment = (loan * moInterestRate * term) / (term - 1.0);
}


cout << fixed << showpoint << setprecision(2);
cout << "Monthly payment: $" << payment << endl;


cout << endl;
cout << setw(5) << "Month" << setw(10) << "Interest";
cout << setw(10) << "Principal" << setw(9) << "Balance" << endl;
cout << "----------------------------------\n";

balance = loan;
for (int month = 1; month <= numPayments; month++)
{
double moInterest,
principal;
moInterest = moInterestRate * balance;
principal = payment - moInterest;
if (month != numPayments)
principal = payment - moInterest;

else
{ principal = balance;
payment = balance + moInterest;
}

balance -= principal;

cout << setw(4) << month << setw(9) << moInterest;
cout << setw(10) << principal << setw(10) << balance<< "\n";
}

for (int month = 1; month <= numPayments; month++)
{
double moInterest,principalSwag,
principal;
double principalBro=500;
moInterest = moInterestRate * balance;

principal = payment- moInterest;
if (month != numPayments)
principal = payment- moInterest;
principalSwag = principalBro - principal;

else
{ principal = balance;
payment = balance + moInterest;
principalSwag = principalBro + principal;
}

balance -= principalSwag;

cout << setw(4) << month << setw(9) << moInterest;
cout << setw(10) << principal << setw(10) << balance << endl;
}

return 0;
}
Last edited on
Topic archived. No new replies allowed.