Last active
August 29, 2015 14:01
-
-
Save dankleiman/526afff884c38089ec74 to your computer and use it in GitHub Desktop.
Cash Register 1
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 amount due | |
puts "What is the amount due?" | |
due = gets.chomp.to_f | |
#input amount tendered | |
puts "What is the amount tendered?" | |
tendered = gets.chomp.to_f | |
#if tendered >= due, print receipt | |
change = (tendered-due).abs | |
change = '%.2f' % change | |
if tendered >= due | |
puts "===Thank You!===" | |
puts "The total change due is $#{change}" | |
puts | |
puts Time.now | |
puts"================" | |
else | |
#otherwise calculate shortfall, warn and exit | |
puts "WARNING: Customer still owes $#{change}! Exiting..." | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Edited to refine float decimal points and condense "shortfall" and "change" to "change" using absolute value.