I just can't get the gradually declines part.
Investment program C++ interest rate declines
Collapse
X
-
Please post the code that you currently have, we can then tell you what you need to change.
But basically, in pseudocode, you would want to do something like this.
Code:loop from 1 to 10 runningTotal = growthFormula(1 year, interest rate, runningTotal) interest rate = interest rate - decrement end loop
Comment
-
Below is my program, but I'm probably not doing anything right here. I need a program that calculates the final value of a ten year, $20,000 investment whose annual return gradually declines from 5% to 2% over that term.
Code:#include <iostream> using namespace std; int main() { float balance = 10000; // account balance float interest = .02; // interest rate float rateOfChange = .001; // interest rate of change for(int i = 0;i < 10; i++) { balance += balance * interest; interest -= rateOfChange; } cout << "The value after ten years is: $" << balance << endl; return 0; }
Comment
-
"gradually declines" is very vague. How about "declines from 5% to 2% in annual 1/4 % decrements?
That way you could reduce the rate of return by a known amount over a defined period.Comment
-
You said you wanted the interest to start at 5% but you have it starting at 2. And you said you want it to drop 3% over the 10 years but you only have it dropping a tenth of a percent each year. If you want it to drop 3 percent, it needs to drop three tenths each year.Comment
-
"gradually declines" is very vague. You may need to seek clarification from the instructor. I can think of three ways to interpret this (listed below in order from easy to hard):- The interest rate declines like a staircase: it stays constant until it abruptly decreases; the changes occur once each year on the anniversary of the investment and each step is the same size each time. (This is what weaknessforcats proposed above.)
- Same as above except the changes occur each day (or each minute or each second).
- No staircase: linear decline (interest is never constant, it changes from moment to moment).
The difficulties with declines #2 and #3 are primarily in determining the right mathematical formula to use ... not so much with implementing the formula on the computer.Comment
Comment