Created
November 18, 2016 13:39
-
-
Save jeccb-zz/9849cf4931d0f49cb37b316710d7c587 to your computer and use it in GitHub Desktop.
This file contains 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
#!/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