In your function. You have if statements. But what if non of the 3 statements ever come true? What if it skips the first, second and third one. What will it then return? It's an int function, it has to return an integer.
#include <iostream>
usingnamespace std;
int A(int n, int m)
{
if(n == 0)
{
return m + 1;
}
if(m == 0 && n > 0)
{
return A(n - 1, 1);
}
if(n > 0 && m > 0)
{
return A(n - 1, A(n, m - 1));
}
return 0;
}
int main()
{
int n, m = 0;
cout << "Enter n and m: " << endl;
cin >> n >> m;
cout << A(n,m);
}
I think i solved the problem. I just changed line number 27 to:
cout << A(m,n);
Now it is not giving an endless loop. I guess the second number must be higher than the first number, that's all. :)
Thanks TarikNeaj and TheIdeasMan for help. :)
Don't you think it would make more sense to fix your function, so that it can correctly handle a situation where the second number is lower that the first?