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
|
#include <iostream>
#include <iomanip>
#include <cctype>
#include <cstring>
#include <cmath>
using namespace std;
void getChoice(char& choice);
void getNumbers(double& beginBalance, double& rate, int& years);
void getCalculations(char choice, double beginBalance, double rate, int years, double calcYInt, double totalYAmt,
double calcMInt, double totalMAmt, double calcWInt, double totalWAmt, double calcDInt, double totalDAmt, char
M, char W, char D);
void getResults(double beginBalance, double rate, int years, double calcYInt, double totalYAmt, double calcMInt,
double totalMAmt, double calcWInt, double totalWAmt, double calcDInt, double totalDAmt);
int main()
{
char choice;
double beginBalance;
double rate;
int years;
double calcYInt;
double totalYAmt;
double calcMInt;
double totalMAmt;
double calcWInt;
double totalWAmt;
double calcDInt;
double totalDAmt;
char M;
char W;
char D;
cout << "This program demonstrates the benefits of compounding interest." << endl << endl;
do {
getChoice(choice);
getNumbers(beginBalance, rate, years);
getCalculations(choice, beginBalance, rate, years, calcYInt, totalYAmt, calcMInt, totalMAmt, calcWInt, totalWAmt,
calcDInt, totalDAmt, M, W, D);
getResults(beginBalance, rate, years, calcYInt, totalYAmt, calcMInt, totalMAmt, calcWInt, totalWAmt, calcDInt,
totalDAmt);
} while (choice != 'E');
cin.get();
return 0;
}
void getChoice(char& choice)
{
cout << "Compare Annual Compounding to:" << endl;
cout << setw(3) << " " << "M - Monthly Compounding" << endl;
cout << setw(3) << " " << "W - Weekly Compounding" << endl;
cout << setw(3) << " " << "D - Daily Compounding" << endl;
cout << setw(3) << " " << "E - Exit Program" << endl << endl;
cout << "Enter Choice from menu above: ";
cin >> choice;
choice = toupper(choice);
cout << endl;
switch (choice) { //start switch plan
case 'M':
cout << "M - Monthly Compounding" << endl << endl;
break;
case 'W':
cout << "W - Weekly Compounding" << endl << endl;
break;
case 'D':
cout << "D - Daily Compounding" << endl << endl;
break;
case 'E':
cout << "E - Exit Program" << endl << endl;
exit(0);
default:
cout << "Please enter a valid menu choice from above: ";
cin >> choice;
break;
} //end switch plan
}
void getNumbers(double& beginBalance, double& rate, int& years)
{
cout << "Enter your beginning balance: ";
cin >> beginBalance;
cout << "Enter an annual interest rate: ";
cin >> rate;
cout << "Enter the years with a whole number: ";
cin >> years;
}
void getCalculations(char choice, double beginBalance, double rate, int years, double& calcYInt, double& totalYAmt,
double& calcMInt, double& totalMAmt, double& calcWInt, double& totalWAmt, double& calcDInt, double& totalDAmt, char
M, char W, char D)
{
double pow;
calcYInt = totalYAmt - beginBalance;
totalYAmt = beginBalance * pow (1 + rate/100), years;
while (choice == M)
{
calcMInt = totalYAmt - beginBalance;
totalMAmt = beginBalance * pow (1 + (rate/100) * 1/12), years;
}
while (choice == W)
{
calcWInt = totalYAmt - beginBalance;
totalWAmt = beginBalance * pow (1 + (rate/100) * 1/52), years;
}
while (choice == D)
{
rate = (rate / 100) * .0027397260;
calcDInt = totalYAmt - beginBalance;
totalDAmt = beginBalance * pow (1 + (rate/100) * 1/365), years;
}
}
void getResults(double beginBalance, double rate, int years, double calcYInt, double totalYAmt,
double calcMInt, double totalMAmt, double calcWInt, double totalWAmt,
double calcDInt, double totalDAmt)
{
cout << "------------------------------------------------" << endl;
cout << setw(28) << "RESULTS" << endl;
cout << "------------------------------------------------" << endl;
cout << "Beginning Balance: " << beginBalance;
cout << "Return after" << years << "years at" << rate << "% interest annually" << endl << endl;
cout << setw(28) << "Return" << setw(14) << "Ending Balance" << endl;
cout << "Compounded Yearly: $ " << calcYInt << " $ " << totalYAmt << endl;
cout << "Compounded Monthly: $ " << calcMInt << " $ " << totalMAmt << endl;
cout << "Compounded Weekly: $ " << calcWInt << " $ " << totalWAmt << endl;
cout << "Compounded Daily: $ " << calcDInt << " $ " << totalDAmt << endl;
}
|