I have to write a program to calculate the monthly, balance and interest paid on a balloon mortgage.
The program must use a for loop to process the payments, and the results must display in a table with the final (balloon) payment showing on the last line.
Output should look like this:
Please enter your mortgage amount: 100000
Please enter your APR: 5
Please enter your payment amount: 1000
Please enter the number of years of your loan: 5
Month Balance Payment Interest
1 100000.00 1000.00 412.50
2 99412.50 1000.00 410.05
loops...to month 60
Balloon Payment: 60046.43
This is what I have been able to do so far:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double mortAmount, payment, apr, years, months;
int paymentCounter;
cout << "Please enter your mortgage amount: ";
cin >> mortAmount; //mortgrage amount from user.
cout << "Please enter your APR: ";
cin >> apr; //gets annual interest rate from user.
if(apr >= 1)
apr = (apr/100); // converts percent to decimal.
cout << "Please enter your payment amount: ";
cin >> payment; //payment amountt from user.
cout << "Please enter number of years of your loan: ";
cin >> years; // number of years from the user.
int numPayments = years * 12;
cout << setiosflags(ios::fixed | ios::showpoint) << setprecision(2); //formats output with decimal two places.
//The table output begins
cout << "Month\tBalance\tPayment\tInterest" << endl;
int dividelist = 0;
for (paymentCounter = 0; paymentCounter <= numPayments; ++paymentCounter)
{
//calculations
double intPaid = (mortAmount - payment) * apr/12; // calculates interest paid on mortgage.
double mortBalance = (mortAmount - payment) + intPaid; // calculates remaining mortgage balance.
if (mortBalance < 0)mortBalance = 0;
mortBalance = mortBalance;
if (dividelist == 0)
{
cout << numPayments << "\t" << mortBalance << "\t" << payment<< "\t" <<intPaid << endl;
}
++dividelist;
}
}
Lost about how to get the output to display as a table properly and run the length of the for loop showing all months of the loan and the final balloon payment. I'd appreciate any insight on how to get the output working properly.

New Topic/Question
Reply


MultiQuote



|