Skip to content

Instantly share code, notes, and snippets.

@dankleiman
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dankleiman/526afff884c38089ec74 to your computer and use it in GitHub Desktop.
Save dankleiman/526afff884c38089ec74 to your computer and use it in GitHub Desktop.
Cash Register 1
#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
@dankleiman
Copy link
Author

Edited to refine float decimal points and condense "shortfall" and "change" to "change" using absolute value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment