Created
March 3, 2014 05:00
-
-
Save sealabcore/9318685 to your computer and use it in GitHub Desktop.
coins
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def dispense_change(cents) | |
change = { "quarters" => 0, "dimes" => 0, "nickels" => 0, "pennies" => 0 } | |
number_of_quarters = cents / 25 | |
if number_of_quarters > 0 | |
change["quarters"] = number_of_quarters | |
end | |
cents = cents % 25 | |
number_of_dimes = cents / 10 | |
if number_of_dimes > 0 | |
change["dimes"] = number_of_dimes | |
end | |
cents = cents % 10 | |
number_of_nickels = cents / 5 | |
if number_of_nickels > 0 | |
change["nickels"] = number_of_nickels | |
end | |
cents = cents % 5 | |
change["pennies"] = cents | |
return change | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment