Skip to content

Instantly share code, notes, and snippets.

@jeccb-zz
Created November 18, 2016 13:39
Show Gist options
  • Save jeccb-zz/9849cf4931d0f49cb37b316710d7c587 to your computer and use it in GitHub Desktop.
Save jeccb-zz/9849cf4931d0f49cb37b316710d7c587 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
class CashMachine
available_cash = [100, 50, 20, 10]
banknotes = {};
print "What value you whish take out? "
value = gets.chomp
value = value.to_i
(0..available_cash.length).each do |cash|
break if cash == 4
count = 0
if available_cash[cash] <= value
count = count + 1
banknotes[available_cash[cash]] = count
value -= available_cash[cash]
end
end
banknotes.each {|k, v|
p "Entregue #{v} de #{k}"
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment