I am working on a program that uses a 2% monthly compounded interest on an initial investment with a monthly deposit, output how many months it will take to reach a certain goal using a recursive function
I am not getting the monthly total to output
Here is my code
int bank(double, double, int); // We are looking for 3 things so we are going to send 3 things
cout << "Please enter your investment : ";
cin >> investment; // user enters investment
cout << "What is your monthly investment : ";
cin >> monthly; // user enter their monthly deposit
month = bank(investment, monthly, month); // calling function
cout << "It will take you " << month << " months to reach at least 500,000";
return 0;
} // end of main
//bank recursive function
int bank(double compound, double monthlyfunds, int addmonth)
{
//cout << compound << "\n";
if (compound >= 500000) // tests whether the investment has reached 500,000
{
return addmonth +1; // adds 1 each time it isnt 500,000
}
else
{
return bank(((compound + monthlyfunds) * 0.02), monthlyfunds, (addmonth + 1)); // recurisve statment: keeps adding up the investments and monthly funds and months while its under 500,000
}
} // end of function