Question: Write a function int investmentLength(double money, double goal, double interestRate) that returns the time it will take to reach the given goal if you start
Write a function int investmentLength(double money, double goal, double interestRate) that returns the time it will take to reach the given goal if you start with the given amount of money and invest at the specified interest rate. (Interest rate will be a %, divide by 100.0 before using). Hints:
Your base case should return 0 - indicating you don't need to invest for any years because you've met your goal
The general case represents one more year of your money having been invested... If you leave the money invested until next year, what would your money, goal and interest rate look like? Which of those would change as you make your recursive call?
Note that the function is declared above main but you will implement it at the bottom of the code (after loops have been disabled).
#include
int investmentLength(double money, double goal, double interestRate);
int main() {
cout << investmentLength(10000, 11000, 5) << endl; cout << investmentLength(10000, 20000, 10) << endl; cout << investmentLength(50, 20000, 4) << endl; return 0; }
//Disable iterative looping structures... #define for "OhNoYouDont" #define while "GetThatOutOfMyKitchen" #define goto "AwwwHeckNo"
//Do not modify anything on or above the line below this //YOUR_CODE_BELOW
//YOUR_CODE - write function here
//YOUR_CODE_ABOVE //Do not modify anything on or below the line above this
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
