Last active
August 29, 2015 14:05
-
-
Save foglabs/996bcfa0890fccc95bd5 to your computer and use it in GitHub Desktop.
Cash Register II
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
input = "beep" | |
subtotal_items = [] | |
cash = 0 | |
time = Time.now | |
#puts "Please enter the amount due: " | |
#price = gets.chomp.to_f | |
while input.downcase != "done" | |
puts "Please enter the sale price:" | |
input = gets.chomp | |
subtotal_items << input.to_f | |
puts "Subtotal: #{'%.2f' % (subtotal_items.inject(:+))}" | |
end | |
puts "Your items are itemized in the item-list below, items:" | |
subtotal_items.each do |item| | |
puts "#{'%.2f' %(item)}" | |
end | |
total = subtotal_items.inject(:+) | |
puts "Please enter the cash tendered:" | |
cash = gets.chomp.to_f | |
if total > cash | |
puts "\n\nThat's not gonna cut it! You're short by $#{'%.2f' %(total-cash)}." | |
else | |
puts "\n\nYour change is $#{'%.2f' %(cash-total)}\n\n===========\nThanks yo!\n===========\n#{time.hour}:#{time.min} #{time.month}-#{time.day}-#{time.year}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment