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 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
#include <iostream>
#include <cmath>
using namespace std ;
/* PROTOTYPES */
void PrintDirections() ;
double GetPmt() ;
double GetRate() ;
int GetNumWeeks() ;
double Compute_FV(double P, double R, int N) ;
void Report_FV(double P, double R, int N, double fv) ;
/* ********************************** */
/* MAIN */
/* ********************************** */
int main ()
{
double P, R, fv;
int N;
PrintDirections();
GetPmt();
GetRate();
GetNumWeeks();
Compute_FV(P, R, N);
Report_FV(P, R, N, fv);
return 0;
}
/* ********************************** */
/* PRINT DIRECTIONS */
/* ********************************** */
void PrintDirections()
{
cout << endl;
cout << "This program will calculate the future value of N\n";
cout << "weekkly payments of P dollars at annual interest\n";
cout << "rate R." << endl;
cout << endl;
cout << "You will be prompted to enter P, R, and N (in that\n";
cout << "order) and then the future value will be\n";
cout << "calculated and written to the screen." << endl;
}
/* ********************************* */
/* GETPMT */
/* ********************************* */
double GetPmt()
{
double P;
cout << endl;
cout << "You must now enter the amount of the payment P in\n";
cout << "decimal form (for example: 54.55). Do *not*\n";
cout << "include a dollar sign ($). Do *not* include any\n";
cout << "commas." << endl;
cout << endl;
cout << "Enter P, the amount of each weekly payment here ===> P = ";
cin >> P;
if (P>0) return P;
else cout << "Cannot recognize value. Try again." << endl;
}
/* ********************************* */
/* GETRATE */
/* ********************************* */
double GetRate()
{
double R;
cout << endl;
cout << "Now you must enter the annual interest rate in\n";
cout << "decimal form (for example: 8.125). Do *not*\n";
cout << "include a percent sign (%). Do *not* include any\n";
cout << "commas." << endl;
cout << endl;
cout << "Enter R, the annual interest rate here ===> R = ";
cin >> R;
if (R>0)
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(3);
return R;
}
else
{
cout << "Cannot recognize value. Try again." << endl;
}
}
/* ******************************** */
/* GETNUMWEEKS */
/* ******************************** */
int GetNumWeeks()
{
double N;
cout << endl;
cout << "Now you must enter the number of weekly payments\n";
cout << "as a whole positive integer (for example: 45). Do *not*\n";
cout << "include a decimal point or any commas." << endl;
cout << endl;
cout << "Enter N, the amount of weekly payments here ===> N = ";
cin >> N;
if (N>0) return N;
else cout << "Cannot recognize value. Try again." << endl;
}
/* ******************************** */
/* COMPUTE_FV */
/* ******************************** */
double Compute_FV(double P, double R, int N)
{
double r = (R/5200) + 1;
double fv = ( P * ((pow(r,N)) - 1) * r ) / (r - 1);
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
return fv;
}
/* ******************************** */
/* REPORT_FV */
/* ******************************** */
void Report_FV(double P, double R, int N, double fv)
{
cout << endl;
cout << "Here is your answer:" << endl;
cout << endl;
cout << "The future value of " << N << " weekly payments of\n";
cout << "$" << P << " at " << R << "% is $" << fv << "." << endl;
cout << endl;
}
/* ******************************** */
/* END */
/* ******************************** */
|