Skip to content

Instantly share code, notes, and snippets.

@gsheppard
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gsheppard/9095159 to your computer and use it in GitHub Desktop.
Save gsheppard/9095159 to your computer and use it in GitHub Desktop.
Cash Register II
=begin
As a cashier
I want to enter the sale price of each item
So that the program will calculate the amount due
Developed by: Anthony Ross, Dan Clarke, and Greg Sheppard
=end
item = ''
trans = []
subtotal = 0
while true
puts "What is the sale price?"
item = gets.chomp
if item == 'done'
break
end
trans << item.to_f
subtotal += item.to_f
puts "\nSubtotal: $#{"%0.2f" % subtotal} \n "
end
puts "Here are your items: \n "
trans.each do |price|
puts "$#{"%0.2f" % price}"
end
puts "\nThe total amount due is $#{"%0.2f" % subtotal} \n "
puts "What is the amount tendered?"
amount_tendered = gets.chomp.to_f
if amount_tendered >= subtotal
puts "\n===Thank You!==="
puts "The total change due is $#{"%0.2f" % (amount_tendered-subtotal)} \n "
puts Time.now.strftime("%m/%d/%Y %I:%M%p") # Format should be 02/12/2013 5:50PM
puts "================"
else
puts " \nWARNING: Customer still owes $#{"%0.2f" % (subtotal-amount_tendered)}! Exiting..."
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment