I trying to make recursive function but I get this error: not all code paths return a value I know why I get this error its because the if not returning something but I don't want it to return something... How to bypass this error? (It should really be just warning)
private double calculate(double money, int months)
{
months--;
if (months != 0)
calculate(profit * 0.3, months);
else
return profit;
}
Edit: I call it like that when user click the button
private void bCalculate_Click(object sender, EventArgs e)
{
profit = double.Parse(tbMoney.Text);
months = int.Parse(tbMonth.Text);
tbPpofit.Text = calculate(profit,months+1).ToString();
}
If I write return like you say it will not give the result that i need
I don't want it to return somethingbut your function must return a double,return calculate(profit * 1.3, months);but we have to guess. And of course recursion isn't the best approach here.