I am trying to make a program that calculates the amount of money saved with compound interest. It needs to output the amount of money saved for each year it accrues. This is what i have so far , using a for loop:
int main ()
{
double p;
double r;
double n;
double savings;
cin>>p;
cin>>r;
cin>>n;
for(int i=0; i<n; i++)
{
savings=p*pow(1.0+r,i);
cout<<savings<<endl;
}
return 0;
}
This out puts the amount saved for each year. But now im having trouble changing this to a recursive function to do the same thing. I have something like this but its not working well...Im new to c++ , sorry for any noob code :\
double calculateBalance(double initial, double rate, double term)
{
int value = initial*pow(1.0+rate,term);
if (term==0) {
return initial;
}
else {
return calculateBalance(value, rate, term-1);
}
}
All help would be GREATLY appreciated!!! Thank you!