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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
#include <iostream>
#include <iomanip>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
using namespace std;
double inputPrincipal();
double inputAIR();
int inputTOF();
int inputPPY();
double computeAmortizedPayment(double p, double ir, double ppy, int n);
void printHeaderInformation(double princ, double ir, double amort, int n);
double computeInterestPortion(double remaining_balance, double ir, int ppy);
void computeAndPrintRows(double p, double ir, double amort, int n, int ppy);
int main()
{
double p = 0.0; // declare a variable to store an input value
double ar = 0.0; // declare a variable to store an input value
int t = 0; // declare a variable to store an input value
int py = 0; // declare a variable to store an input value
double a = 0.0; // stores the amortized payment
p = inputPrincipal(); // input the Principal
ar = inputAIR(); // input the Annual Interest Rate
t = inputTOF(); // input the Term of the Loan
py = inputPPY(); // input the Payments per Year
// compute the Amortized Payment
a = computeAmortizedPayment(p, ar, t, py);
// output the value...
printHeaderInformation(p, ar, t, py);
cout.precision(2);
// exit the program with success (0 == success)
return 0;
}
double inputPrincipal()
{
double num = 0.0;
bool is_valid_input = false;
while (is_valid_input == false)
{
cout << "Please enter an Principal that is > 0: ";
cin >> num;
if (num > 0)
{
is_valid_input = true;
}
else
{
cout << "ERROR: The Principal must be greater than zero (0)." << endl;
}
}
return num;
}
double inputAIR()
{
double rate = 0.0;
bool is_valid_input = false;
while (is_valid_input == false)
{
cout << "Please enter a Annual Interest Rate that is in the range of [1-100]: ";
cin >> rate;
if (rate > 1 && rate <= 100)
{
is_valid_input = true;
}
else
{
cout << "ERROR: The AIR has to be [1-100]" << endl;
}
}
return rate;
}
int inputTOF()
{
int loan = 0;
bool is_valid_input = false;
while (is_valid_input == false)
{
cout << "Please enter a Term of the Loan that is in the range of [10-30]: ";
cin >> loan;
if (loan > 10 && loan <= 30)
{
is_valid_input = true;
}
else
{
cout << "ERROR: The TOF has to be [10-30]" << endl;
}
}
return loan;
}
int inputPPY()
{
int pay = 0;
bool is_valid_input = false;
while (is_valid_input == false)
{
cout << "Please enter a Payments per Year that is in the range of [1-12]: ";
cin >> pay;
if (pay > 1 && pay <= 12)
{
is_valid_input = true;
}
else
{
cout << "ERROR: The PPY has to be [1-12]" << endl;
}
}
return pay;
}
double computeAmortizedPayment(double p, double ir, double ppy, int n)
{
double a = 0.0;
a = (p * ir * pow((ir + 1), n)) / (pow((ir + 1), n) - 1);
return a;
}
void printHeaderInformation(double princ, double ir, double amort, int n)
{
cout << "\nBeginning Principal: " << princ << endl;
cout << "Annual Interest Rate: " << ir << endl;
cout << "Total Payments: " << n << endl;
cout << "Payment Amount: " << amort << endl;
cout << setw(5) << "\nPayment#" << setw(20) << "Interest Due" << setw(20) << "Principal" << setw(25) << "Balance Remaining" << endl;
}
double computeInterestPortion(double remaining_balance, double ir, int ppy)
{
return (remaining_balance * (ir / 100.0)) / ppy;
}
void computeAndPrintRows(double p, double ir, double amort, int n, int ppy)
{
}
|