I am trying to make a recursive program that calculates interest per year.It prompts the user for the startup amount (1000), the interest rate (10%)and number of years(1).(in brackets are samples)
Manually I realised that the interest comes from the formula YT(1 + R)----- interest for the first year which is 1100.
2nd year YT(1 + R/2 + R2/2) //R squared
2nd year YT(1 + R/3 + R2/3 + 3R3/) // R cubed
How do I write a recursive program that will calculate the interest? Below is the function which I tried
//Latest after editing
double calculateInterest2(double start, double rate, int duration)
{
if (0 == duration) {
return start;
} else {
return (1+rate) * calculateInterest2(start, rate, duration - 1);
}
}