Created
August 13, 2014 15:16
-
-
Save akcrono/d8513c81987cd3c619b7 to your computer and use it in GitHub Desktop.
chash register program for Launch Academy
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
require 'bigdecimal' | |
require 'bigdecimal/util' | |
values = [] | |
puts 'What is the sale price?' | |
print '>' | |
input = gets.chomp | |
while input != 'done' | |
values << input.to_f | |
puts 'What is the sale price?' | |
print '>' | |
input = gets.chomp | |
end | |
puts "Here are your item prices:\n\n" | |
values.each do |value| | |
puts "$#{sprintf("%.2f", value)}" | |
end | |
puts "\nWhat is the amount tendered?" | |
print '>' | |
cash = gets.chomp.to_f | |
total = values.inject(0) { |result, element| result + element } | |
if total > cash | |
puts "WARNING: Customer still owes $#{sprintf("%.2f", (total - cash))}! Exiting..." | |
exit | |
end | |
puts '===Thank You!===' | |
puts sprintf("%.2f", cash) | |
puts "The total change due is #{sprintf("%.2f", (cash - total))}" | |
puts | |
puts "#{Time.new.strftime('%m/%d/%Y %l:%M%p')}" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment