Skip to content

Instantly share code, notes, and snippets.

@wejn
Last active December 13, 2015 19:58
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 wejn/4966076 to your computer and use it in GitHub Desktop.
Save wejn/4966076 to your computer and use it in GitHub Desktop.
add shebang, fix loop, fix conversion, fix formatting
#!/usr/bin/env ruby
# encoding: utf-8
bill = nil
loop do
print "\rHow much you bill was (CZK): "
bill = gets
begin
bill = Integer(bill)
break
rescue Object
end
end
tipSize = rand(25)
tip = (bill/100.0*tipSize).round
total = bill+tip
length = total.to_s.length + 1
puts("Bill: %#{length}i" % bill)
puts("%d%% tip: %#{length+1-tipSize.to_s.length}i" % [tipSize, tip])
puts("="*(8+length))
puts
puts("Total: %#{length}i" % total)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment