Master C

Splitting the bill

Splitting the bill

A restaurant's card machine adds a tip to the bill and then divides the whole thing evenly between everybody at the table. It works entirely in pence, because it is not willing to lose half a penny anywhere, and it always rounds in the customer's favour by throwing away anything left over.

Write share_pence. Work out the tip as bill_pence * tip_percent / 100, add it to the bill, and divide the total by the number of people. Every one of those divisions is whole number division, so the remainder is discarded each time.

Worked example

Input:  bill_pence = 1999, tip_percent = 12, people = 3

1999 * 12 = 23988,  23988 / 100 = 239   (239.88, remainder thrown away)
1999 + 239          = 2238
2238 / 3            = 746

Output: 746

Constraints

  • bill_pence is between 0 and 10000000.
  • tip_percent is between 0 and 100.
  • people is at least 1.
  • The answer is the share for one person, in pence.
Code

Run your code to see how it does on the examples. Submit also runs the hidden cases.