Hi everyone, I posted this on the General C++ board but I have a feeling that might have been the wrong place.
If this is a double post or not allowed please just delete.
--
I'm creating an Interest Compounding Calculator, and I'm trying to have it execute a while loop inside a while loop.
So far it will give you the interest and the yield from the highest possible interest rate (which the user inputs) and 1. I want it also to repeat this for every year leading upto the number of years the user wants it to run. so eg: if the user wants it to run for 5 years and an interest rate of 5.
I want it to have an output for year 5, and the yields for percents 5, 4, 3, 2, 1
Year 4 and the yields for percents 5, 4, 3, 2, 1
and etc.
I've set up the two while loops but only one of them runs.
Here's my code, thanks for your help!
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
|
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
void welcome()
{
cout << " Hello and Welcome to the Compounding Calculator\n"
" -----------------------------------------------\n"
" Here you can calculate how much your investment will yield\n"
" in various scenarios.\n"
" Lets Get Started!" << endl;
cout << "-------------------------------------------------\n";
cout << " ***Please enter all values numerically***\n" << endl;
}
void interestCalculation(double& totalValue, double& investmentInt, double& interest, double& length)
{
while (interest>0)
{
totalValue = ((investmentInt*(interest/100))+investmentInt)*length;
cout << interest << "% = $" << totalValue << " ";
--interest;
}
cout << endl;
}
void investEval(double& investInt)
{
cout << " Please enter the amount of your initial investment: $";
cin >> investInt;
}
void interestEval(double& interestRate)
{
cout << " Please enter the highest amount of interest you approximate you will get: ";
cin >> interestRate;
}
void lengthEval(double& length)
{
cout << " For how many years do you want to calculate? " ;
cin >> length;
}
int investmentProgram()
{
double s;
welcome();
while(true)
{
char choice;
double investment, interestR, n, value;
investEval(investment);
interestEval(interestR);
lengthEval(n);
for (int x=n; x>0; --x)
{
interestCalculation(value, investment, interestR, n);
cout << value;
--n;
}
cout << " Would you like to make another calculation?" << endl;
cout << " Enter 'y' for yes and 'n' for no: ";
cin >> choice;
if (choice == 'y')
{
continue;
}
else
{
break;
cout << endl;
}
}
}
int main()
{
investmentProgram();
system("pause");
return 0;
}
|