Back to Challenge Set 2

Code Challenge: Tip Calculator

Difficulty  

divider

The Brief

What they asked for
My family goes out to eat every Friday and I am tired of
doing tip math on my phone at the table. Let me type in the
bill and the percent I want to leave, and tell me the tip
and the total.

Write your requirements list before you write any code. Input, calculate, output, and anything you had to decide for yourself.


Notes

  • Two things come from the person running the program: the bill and the tip percent.
  • Both need double.Parse before you can do arithmetic with them.
  • A percent is not the number you multiply by directly — 18 percent means you multiply by 18 / 100.0, not by 18.
  • Money looks wrong with a long decimal tail. Print both the tip and the total with :F2.

Where to Start

Only one-star challenges have this section. If you already know how to begin, skip it — and when you move up to two stars, working out the order yourself is part of the job.

  1. Get the bill and the tip percent, and parse both with double.Parse.
  2. Turn the percent into a decimal fraction before you multiply.
  3. Multiply the bill by that fraction to get the tip.
  4. Add the tip to the bill to get the total, and print both with :F2.

Sample Output

Sample Output
Bill amount? 42.50
Tip percent? 18
Tip: $7.65
Total: $50.15

Verified in a real run — a 42.50 bill at 18 percent comes to exactly $7.65 in tip and $50.15 total.


Submit

Your requirements list and your program file, named cc-tip-calculator.

Commence Challenge