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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
#include <iostream>
using namespace std;
void GetLoanAmt(float& loanAmount);//gets loan amount from user
void GetRest(float& monthlyInterest, int & numberOfYears);//calls GetInterest function and gets
//numberOfYears from user
void GetInterest(float& monthlyInterest);//gets yearly interest from user
void DeterminePayment(float loanAmount, float monthlyInterest, int numberOfPayments, float&
payment);//calculates monthly payment amount
void PrintResults(float loanAmount, float yearlyInterest,
int numberOfPayments, float payment,
float totalInterest);//prints results on screen.
void GetLoanAmt(float& loanAmount)
{
cout << endl;
}
void GetRest(float& monthlyInterest, int & numberOfYears)
{
cout << "Please enter an interest rate: " << endl;
cin >> monthlyInterest;
cout << "Enter number of years on the loan : " << endl;
cin >> numberOfYears;
}
void GetInterest(float& monthlyInterest)
{
float yearlyInterest = 0;
yearlyInterest = monthlyInterest * 12;
cout << endl;
}
void DeterminePayment(float loanAmount, float monthlyInterest, int numberOfPayments, float & payment)
{
payment = loanAmount * monthlyInterest;
cout << endl;
}
void PrintResults(float loanAmount, float yearlyInterest, int numberOfPayments, float payment, float totalInterest)
{
int numberOfYears;
cin >> numberOfYears;
totalInterest = yearlyInterest * numberOfYears;
cout << "Here are the results." << endl;
cout << "Loan Amount: " << loanAmount<< endl;
cout << "Interest Rate: " << yearlyInterest << endl;
cout << "Number of Payments: " << numberOfPayments << endl;
cout << "Monthly Payment: " << payment << endl;
cout << "Total Interest Paid: " << totalInterest << endl;
}
int main()
{
float loanAmount;
float monthlyInterest;
int numberOfYears;
int numberOfPayments = 0;
float payment;
float yearlyInterest = 0;
float totalInterest = 0;
cout << "Welcome to input loan amount program." << endl;
cout << "Please remember that negative loan amount terminates the program!!!" << endl;
cout << "Please enter a loan amount: ";
cin >> loanAmount;
while (loanAmount < 0)
{
cout << "Thanks for your business. BYE! Hope to see you later.You will receive a customer satisfaction survey to your email address." << endl;
break;
}
GetLoanAmt(loanAmount);
GetRest(monthlyInterest, numberOfYears);
GetInterest(monthlyInterest);
DeterminePayment(loanAmount, monthlyInterest, numberOfPayments, payment);
PrintResults(loanAmount, yearlyInterest, numberOfPayments, payment, totalInterest);
return 0;
}
|