Back to Set 1

Code Challenge: Tip Split

Difficulty  

divider

The Brief

What they asked for
We went out for dinner, six of us, and nobody can work out
what they owe. Ask me the bill, how many people, and what
tip we are leaving, and tell me what each person pays.

Write your requirements list before you write any code. What goes in, what gets worked out, what comes out, and every question the brief did not answer.


Notes

  • Three things go in and one comes out. Get that working before you worry about anything else.
  • Is the tip worked out on the whole bill or on each share? The two give the same answer here. Say which one you did and why.
  • Money has two decimal places and Lua does not know that. Decide what you are doing about it and write it down.
  • Test it with a bill that does not divide evenly.

Sample Output

Sample Output
Bill total: 84.50 [Enter]
How many people? 6 [Enter]
Tip percent: 18 [Enter]
Each person pays: 16.62

Your numbers will differ. Run it three times with different inputs and keep the outputs.


Submit

Your requirements list and your program folder, named cc-tip-split.

Commence Challenge