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 make_change(amount, coins = [25,10,5,1]) | |
puts "Input doesn't make sense. You have change leftover." if amount % coins.last != 0 | |
change = {} | |
coins.each do |coin| | |
x = amount/coin | |
amount = amount - (x * coin) | |
coin_key = coin.to_s | |
change[coin_key] = x | |
end | |
change.each {|k,v| puts "You have #{v}, #{k} cent coin(s)" if v > 0} |
NewerOlder