Perhaps put brackets around 'validSize - 1' so that it becomes '(validSize - 1)', sometimes compilers struggle to recognise all of it as one value without brackets.
Secondly, and I know this is true for Java, not so sure about C++, but I'll try anyway: your return statements probably aren't valid because your method is defined as a void.
Replace the word 'void' with 'int' everywhere you've used it, see if that helps.
Here is my code:
#include
using namespace std;
void recursive(int validChange[], int validSize, int amount);
int main()
{
int amount1 = 0;
int change[5] = { 1, 5, 10, 15, 25 };
cout << "Enter an amount of change\n ";
cin >> amount1;
cout << recursive(change, 5, amount1) << " ";
system("PAUSE");
return 0;
}
void recursive(int validChange[], int validSize, int amount)
{
if (amount == 0)
{
return 1;
}
if (amount < 0)
{
return 0;
}
else
{
return recursive(validChange, validSize - 1, amount) + recursive(validChange, validSize, amount - validChange[validSize - 1]);
}
}
I am having errors with return recursive(validChange, validSize - 1, amount) and the return 0; return 1; portions. Also am having errors in trying to cout the numbers. Thanks!