Created
December 25, 2013 18:42
-
-
Save mikeadeleke/8125812 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 "Enter the price of your meal before tax" | |
meal = Float(gets) | |
puts "What is the tax rate in your area?" | |
tax = Float(gets) | |
puts "What is the tip rate in your area?" | |
tip = Float(gets) | |
def calculate(base, percent) | |
amount = base * percent / 100 | |
end | |
tax_value = calculate(meal, tax) | |
meal_with_tax = tax_value + meal | |
tip_value = calculate(meal, tip) | |
total_cost = tip_value + meal_with_tax | |
puts "The pre-tax cost of your meal was $#{meal}." | |
puts "At #{tax}%, tax for this meal is $#{tax_value}." | |
puts "For a #{tip}% tip, you should leave $#{tip_value}." | |
puts "The grand total for this meal is then $#{total_cost}." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment