I'm having a tough time conceptualizing this problem. I have a recursive function computing the number of possible combinations of two numbers. I have it working fine, just need one thing sorted out. My output needs a counter to increment each recursive step. Like this:
Level 1:
...
Level 2
...
Level 3
...
The combinations are printing out correctly but I can't figure out how to increment the level correctly each time. Any help would be appreciated. Here's the code:
#include<iostream>
using namespace std;
long Combinations(int y,int x,int level)
{
if(x==1)
{
return y;
}
else if(x==y)
{
return 1;
}
else
{
cout << "Recursive Level " << level << endl;
cout << "y = " << y << " x = " << x << endl;
return Combinations(y-1,x-1,level+1) + Combinations(y-1,x,level);
}
}
int main()
{
long result;
result = Combinations(8,4,1);
cout << result << endl;
return 0;
}