#1: Tip Calculator

You’ve finished eating at a restaurant, and received this bill:

  • Cost of meal: $44.50
  • Restaurant tax: 6.75%
  • Tip: 15%

You’ll apply the tip to the overall cost of the meal (including tax).

STEP 1:

First, we assign these variables meal, tax and tip to their values:

meal = 44.50
tax = 6.75 %
tip = 15%

We also need to get rid of the percentage and turn them into decimals, so they look like
meal = 44.50
tax = 0.0675
tip = 0.15

STEP 2″

Create the variable tax and set it equal to the decimal value of 6.75%.

tax = 6.75/100

STEP 3:

Set the variable tip to decimal value of 15% on line 5.

tip = 15.0/100

STEP 4:

On line 7, reassign  meal to the value of itself + itself * tax. And yes, you’re allowed to reassign a variable in terms of itself!

We’re only calculating the cost of meal and tax here. We’ll get to the tip soon.

Assign the variable total to the sum of meal + meal * tip on line 8. Now you have the total cost of your meal!