Lesson goal: Calculating a tip in a restaurant

Previous: Mathematical expressions with variables | Home | Next: Calculate a tip (with keyboard input)

With the use of variables in mathematical expressions, you can program the computer to do useful calculations for yourself. How about the tip in a restaurant? If you know the cost of a meal $(meal)$, and decide what percentage to leave the server $(per)$, the tip will be $tip=per/100\times meal$. With this, the total cost of the meal will be $total=meal+tip$. See if you can finish the code below, and have a "tip calculator."

Now you try. Try finishing this tip calculator based on the formulas discussed above.

Type your code here:

See your results here:

Show a friend, family member, or teacher what you've done!

Here is a share link to your code:

Does your code work? Want to run it on your iPhone?

Here's your code:

  1. Use [Control]-[C] (Windows) or [⌘]-[C] (MacOS) to copy your code.

  2. Paste it using [Control]-[V] (Windows) or [⌘]-[V] (MacOS) into this page

  3. Then click the "Use on iPhone" button that you'll see.