Você está na página 1de 3

/*****************************************************************************

Nathan Kondor
INFO_1522_WW
06/28/2016
C++ Programming - Program Design Including Data Structures
Chapter 5 - Exercise 21
Enhance your program from exercise 20 by first telling the user the minimum
monthly payment and then prompting the user to enter in the monthly payment.
Your last payment might be more than the remaining loan amount and interest on
it. In this case, output the loan amount before the last payment and the actual
amount of the last payment. Also, output the total interest paid.

(Reference: Ch5 Ex-20)


When you borrow money to buy a house, a car, or for some other purpose, you
repay the loan by making periodic payments over a certain period of time.
Suppose you borrow $1000 at the interest rate of 7.2% per year and the payments
are monthly. Suppose your monthly payment is $25. Now the interest is 7.2% per
year and the payments are monthly, so the interest rate per month is 7.2/12=0.6%.
The first month's interest on $1000 is $1000 x 0.006 = 6. Because the payment
is $25 and the interest for the first month is $6, the payment towards the
principal amount is 25-6= 19. This means after making the first payment, the
loan amount is 1000-19=981. So the interest rate for the second payment, the
interest is calculated on $981. So the interest for the second month is 981
x 0.006=5.886 which is approx. $5.89. This implies the payment towards the
principal is $25-5.89= 19.11 and the remaining balance after that second
payment is $961.89. This process is repeated until the loan is paid.
Write a program that accepts as input the loan amount, the interest rate
per year, and the monthly payment. (Enter the interest rate as a percentage).
The program then outputs the number of months it would take to repay the loan.
(Not that if the monthly payment is less than the first month's interest, then
after each payment, the loan amount will increase. (In this case the program
must warn the borrower that the monthly payment is too low and with this
monthly payment the loan amount could not be repaid.)
*****************************************************************************/
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
//Main function
int main()
{
//Input variables

double principle = 0;
double aPR = 0;
double mP = 0;

//Loan Principle Amount


//Annual Percentage Rate
//Monthly Payment

//Output variables
double newAPR = 0;
//APR variable for calculation
double newPrinciple = 0;
//Principle variable for calculation
double adjNewPrinciple = 0;
//Adjusted New Principle
double mPR = 0;
//Monthly Precrentage Rate
double minPayment = 0;
//Minimum Payment
double fMI = 0;
//First Months Interest Payment
double mIP = 0;
//Monthly Interest Payment
double totalInterest = 0; //Total Interest Amount
int monthCount = 0;

//Month counting variable

//This statement takes care of the decimal places


cout << fixed << showpoint << setprecision(2);
//Input from user
cout << "Enter the amount of the loan: $";
cin >> principle;
newPrinciple = principle;
cout << "Enter the interest amount: %";
cin >> aPR;
newAPR = aPR;
mPR = newAPR*0.01 / 12;
fMI = principle * mPR;
minPayment = fMI + 1;
cout << "Your minimum monthly payment is: $" << minPayment << endl;
cout << "Enter the monthly payment: $";
cin >> mP;
//Program logical loop & Mathematics
if (mP <= fMI) {
cout << "The monthly payment is too low, and with this monthly "
<< "payment the loan amount could not be repaid." << endl;
exit(0);
}
else
while (newPrinciple >= 0) {
adjNewPrinciple = mP - newPrinciple*mPR;
mIP = newPrinciple * mPR;
totalInterest = totalInterest + mIP;
newPrinciple = newPrinciple - adjNewPrinciple;
monthCount++;
//Output to user
if (newPrinciple <= mP && newPrinciple >= 0) {
cout << "Your loan amount before final payment is: $" << newPrinciple
<< endl;
cout << "Your final payment is: $" << newPrinciple + mIP << endl;

}
}
cout << "Your loan will take approximately " << monthCount << " months to pay off." << endl;
cout << "Your total interest paid is: $" << totalInterest << endl;
return 0;
}

Você também pode gostar