#recursive function doesnt return anything
1 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
do you call it?
yes
int deno[3] = {1, 5, 10};
cout << change(21,deno);
you sure it actually terminates?
You can print money in the function
you'll see it's stuck at 1
int change(int money, int denominations[]) {
if (money == 0)
return 0;
int max = 0, n = 3;
for (int i = 0; i < n; i++) {
if ((denominations[i] > max) && (denominations[i] <= money))
max = denominations[i];
}
return (1 + change(money - max, denominations));
}
``` this works
denominations[i] <= money instead of denominations[i] < money