Created
October 21, 2013 20:01
-
-
Save benjaminEwhite/7089974 to your computer and use it in GitHub Desktop.
Thinkful | Ruby on Rails | Tip Calculator Part 2
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
# first we get user inputs for our variables | |
# and convert them to Floats (they'll initially be strings). | |
puts "Please enter the cost of your meal (e.g., 22.45): $ " | |
meal_cost = Float(gets) | |
puts "Please enter tax rate as a percentage (e.g., 12.5 or 15): " | |
tax_percent = Float(gets) | |
puts "Please the tip percentage you'd like to leave (e.g., 18): " | |
tip_percent = Float(gets) | |
tax_value = meal_cost * tax_percent/100 | |
meal_with_tax = meal_cost + tax_value | |
tip_value = meal_with_tax * tip_percent/100 | |
total_cost = meal_with_tax + tip_value | |
print "The pre-tax cost of your meal was $%.2f.\n" % meal_cost | |
print "At %d%%, tax for this meal is $%.2f.\n" % [tax_percent, tax_value] | |
print "For a %d%% tip, you should leave $%.2f.\n" % [tip_percent, tip_value] | |
print "The grand total for this meal is then $%.2f.\n" % total_cost | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
puts "Please enter the cost of your meal (e.g., 22.45): $ "
meal_cost = Float(gets)