Skip to content

Instantly share code, notes, and snippets.

@foglabs
Last active August 29, 2015 14:05
Show Gist options
  • Save foglabs/996bcfa0890fccc95bd5 to your computer and use it in GitHub Desktop.
Save foglabs/996bcfa0890fccc95bd5 to your computer and use it in GitHub Desktop.
Cash Register II
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