| "; // display the change value as a header for the table for ($k=100; $k>0; $k--) { echo " | $k | "; } echo "||
|---|---|---|---|
| "; // display the change value as a header for the table for ($k=100; $k>0; $k--) { echo " | $k | "; } echo "Averages | |
| $coin | "; } else { echo "|||
| $coin | "; } $count = 0; for ($money=100; $money>0; $money--) { // and for each MONEY AMOUNT... echo " "; $coins = 0; $denom = array($penny, $nickle, $dime, $quarter, $coin); rsort($denom); // LARGEST DENOM while ($money >= $denom[0]) { $money = $money - $denom[0]; $coins++; } while ($money >= $denom[1]) { $money = $money - $denom[1]; $coins++; } while ($money >= $denom[2]) { $money = $money - $denom[2]; $coins++; } while ($money >= $denom[3]) { $money = $money - $denom[3]; $coins++; } while ($money >= $denom[4]) { $money = $money - $denom[4]; $coins++; } if ($coins == 1) { echo "$coins | "; } else { echo "$coins | "; } $total = $total + $coins; $money = 100 - $count; $count++; } $average = $total / 100; $averages[$coin] = $average; echo "$average |
"; print_r($averages); echo ""; ?>
With our current common coinage (excluding half and whole dollars), the current average number of coins needed when making change is 4.74. If we introduced a 2¢ or 3¢ piece, the average number of coins would drop to 3.94 coins. That's a drop of almost an entire coin!