/**********************************************
Write a function that gives change, i.e. it
takes an amount as argument, and it prints out
P's,N's,D's, and Q's - one for each penny,
nickle, dime and quarter it gives out.
Ex: If Amount is 33, it would print out
QNPPP
If you don't see why, would you care to
play some poker?
Your function should be recursive, and here's
some simple rules to help you (let A be the
amount you need change for):
1) If A is 0, don't give anything!
2) If A > 0, give out one of the largest
denomination not exceeding A, then make
change for the remaining amount.
**********************************************/
#include <iostream>
using namespace std;
void change(int A);
int main()
{
int Amount;
cout << "Enter amount: ";
cin >> Amount;
cout << "Change to give is: ";
change(Amount);
cout << endl;
return 0;
}
void change(int A)
{
// BASE CASE
if (A == 0)
return;
// RECURSIVE CASE
int D;
if (A >= 25)
{
D = 25;
cout << 'Q';
}
else if (A >= 10)
{
D = 10;
cout << 'D';
}
else if (A >= 5)
{
D = 5;
cout << 'N';
}
else
{
D = 1;
cout << 'P';
}
change(A - D);
}