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
|
#include <iostream>
#include <math.h> //pow();
using namespace std;
/* float calcInterest1 ( the first argument for the principal,
the second argument for the number of years of deposit,
the third argument for the annual interest). */
/* A = P ( 1 + (r/n) ) ^(n * t)
P = principal amount (the initial amount you borrow or deposit)
r = annual rate of interest (as a decimal)
t = number of years the amount is deposited or borrowed for.
A = amount of money accumulated after n years, including interest.
n = number of times the interest is compounded per year */
float calcInterest1 ( double P, double N, double A )
{
float compoundInterest;
compoundInterest = (pow(P*(1+A), N));
cout << "--------" << "Compound Interest for the Function <calcInterest1>" << "--------" << endl
<< endl;
cout << "Compound Interest Is: " << compoundInterest << endl
<< endl;
return 0.0;
}
/* float calcInterest2 ( the first argument for the principal,
the second argument for the number of years of deposit,
the third argument for the annual interest)
*/
float calcInterest2 ( double &P, double N, double A)
{
float compoundInterest;
compoundInterest = (pow(P*(1+A), N));
cout << "--------" << "Compound Interest for the Function <calcInterest2>" << "--------" << endl
<< endl;
cout << "Compound Interest Is: " << compoundInterest << endl
<< endl;
return 0.0;
}
/* In the main routine, you consider the following test case:
Principal = $200,000.00
Year to save = 10 years
Annual Interest = 3%
*/
int main()
{
double P = 200000.00;
int N = 10;
double A = 0.03;
calcInterest1(P, N, A);
calcInterest2(P, N, A);
system("pause");
return 0;
}
|