Last active
August 29, 2015 14:01
-
-
Save Murphydbuffalo/b733b24d06aa998f96fd to your computer and use it in GitHub Desktop.
Solution to the cashier problem
This file contains hidden or 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
#prompted for amount due | |
puts "How much does the customer owe?" | |
bill = gets.chomp.to_f.round(2) | |
#prompted for amount received | |
puts "How much did the customer pay?" | |
payment = gets.chomp.to_f.round(2) | |
#gives change and time of transaction or provides message and exits if not enough is provided | |
change = (payment-bill).abs | |
#if payment > bill return the difference of the two and the time | |
if payment > bill | |
puts Time.new | |
puts "Your change is $#{change}!" | |
#else warn cashier payment is insufficient and exit | |
elsif payment == bill | |
puts "Exact change! Much appreciated." | |
else | |
puts "Sorry you still owe $#{change}!" | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment