Last active
August 29, 2015 13:56
-
-
Save gsheppard/9095159 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
=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