I try to make a recursive function, but I get this error: not all code paths return a value . I know why I get this error because if does not return something, but I do not want to return something ... How to get around this error? (This should be just a warning)
private double calculate(double money, int months) { months--; if (months != 0) calculate(profit * 0.3, months); else return profit; }
Edit: I call it that when the user clicks a 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, as you say, it will not give the result that I need
source share