I think, you need to make your compute_coins a bit generic. Also, a bit of change in signature is required. What type of coins it will return. lets take an enum
1 2 3 4 5 6 7 8
|
enum typeofcoin
{
quarter = 1,
dime = 2,
penny = 3
};
typeofcoin computeCoin(int coinValue, int& number, int& amountLeft);
|
Multiple calls to computeCoin will be required. Lets say for 86;
call1:
computeCoin(86, pm1, pm2);
pm1 will have 3, pm2 will have 11 and return type will be quarter;
call2:
computeCoin(11, pm1, pm2);
pm1 will have 1, pm2 will have 1 and return type will be dime.
call3:
computeCoin(1, pm1, pm2);
pm1 will have 1, pm2 will have 0 and return type will be dime.
as soon you see pm2 is 0, which means all the change is returned, you will stop.
in the main, you can do something like this:
1 2 3 4
|
while(pm2 != 0)
{
computeCoin(86, pm1, pm2)
}
|
make sense ? Could you try to write computeCoin now ?