Skip to content

Instantly share code, notes, and snippets.

@andyweiss1982
Last active August 29, 2015 14:04
Show Gist options
  • Save andyweiss1982/de6abd816d8a3c86761f to your computer and use it in GitHub Desktop.
Save andyweiss1982/de6abd816d8a3c86761f to your computer and use it in GitHub Desktop.
Tip calculator
puts "How much did the meal cost?"
inputok = false
until inputok == true do
mealprice = gets.chomp.to_f
if mealprice > 0
mealprice = (mealprice*1.20).round(2).to_s.split(".")
inputok = true
else
puts "I only understand numbers. Please input a number."
inputok = false
end
end
if mealprice[1].to_i < 10
mealprice[1] = (mealprice [1]).to_s + "0"
end
mealprice = mealprice.join(".")
puts "You should pay $#{mealprice} including a 20% tip."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment