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 87 88 89 90 91 92 93 94 95 96 97
|
// include statement(s).
#include <iostream>
#include <cmath>
#include <iomanip>
// using namespace statement.
using namespace std;
// Declare named constants, if necessary.
//functions prototypes
double monthlyPayment ();
double unpaidBalance ();
int main()
{
double x;//the monthly payment from the function()
double y;//balance left on the loan from function()
char choice;//to start or exit the program
cout << fixed << showpoint << setprecision (2);
cout <<"Enter (Y) to calculate the monthly payment and"
<<" balance left on your morgage.\n\n"
<<"Enter (Q) to quit the program.";
cin >> choice;
cout << endl;
if (choice == 'Y' || choice == 'y')
{
a = monthlyPayment();
cout <<"The monthly payment is : $ " << a << endl;
y = unpaidBalance();
cout <<"The balnce of the loan is: " << y << endl;
cout <<"Enter (Y) to find periodic payment and"
<<" balance left on your morgage.\n\n"
<<"Enter (Q) quit the program.";
cin >> choice;
cout << endl;
}//end if loop
else
cout <<"good bye. " << endl;
return 0;
}
double monthlyPayment ()
{
double loanAmount, rValue, i, r;
int m, t, n, monthlyRate;
cout <<"Enter the loan amount: ";
cin >> loanAmount;
cout << endl;
cout <<"Enter the interest per year as a number: ";
cin >> r;
cout << endl;
cout <<"Enter the payments in one year: ";
cin >> m;
cout << endl;
cout <<"Enter the number of years for the loan: ";
cin >> t;
cout << endl;
i = r / (m * 100);
n = m*t;
rValue = loanAmount * i / (1 - pow(1+i,-n));
return rValue;
}
double unpaidBalance()
{
double k, i, x, n, lValue;
//i am not sure how to get the rValue from 1st function
//and use it in the 2nd function
x = monthlyPayment();
lValue = x * ((1 - pow(1+i,n)) / i);
cout <<"Enter the number of payments made: ";
cin >> k;
cout << endl;
return lValue;
}
|