Last active
August 29, 2015 14:04
-
-
Save andyweiss1982/de6abd816d8a3c86761f to your computer and use it in GitHub Desktop.
Tip calculator
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
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