curious if anyone wants to try writing a function for:
function that will accept an integer number of cents and print out a breakdown into pennies, nickels, dimes, quarters
i tried it but it wasn’t pretty.
curious if anyone wants to try writing a function for:
function that will accept an integer number of cents and print out a breakdown into pennies, nickels, dimes, quarters
i tried it but it wasn’t pretty.
<?php
function InCents($amount)
{
$quarters = floor($amount/25);
$amount -= ($quarters * 25);
$dimes = floor($amount/10);
$amount -= ($dimes * 10);
$nickels = floor($amount/5);
$amount -= ($nickels * 5);
$pennies = $amount;
return array('quarters' => $quarters, 'dimes' => $dimes, 'nickels' => $nickels, 'pennies' => $pennies);
}
var_dump(InCents(101));
var_dump(InCents(100));
var_dump(InCents(99));
var_dump(InCents(90));
var_dump(InCents(75));
elegant, thanks!
Nice! :award: