Master C++

Till receipt line

Till receipt line

A café till prints one line per item on the receipt. It keeps every price in pence, because pence are whole numbers and pounds are not, and it wants each line to read the same way whatever was bought.

Write receiptLine, which is given the name of the item, how many were bought, and the price of one of them in pence. Return the line: the quantity, a space, x, a space, the item, a space, =, a space, the total in pence, and the letter p.

Worked example

Input:  item = "Coffee", quantity = 3, pencePerItem = 250
Output: "3 x Coffee = 750p"

Three coffees at 250p each come to 750p.

Input:  item = "Tea", quantity = 1, pencePerItem = 180
Output: "1 x Tea = 180p"

Constraints

  • item is between 0 and 40 characters long.
  • quantity is between 0 and 1000.
  • pencePerItem is between 0 and 100000.
  • Both numbers are whole numbers, and so is the total.
  • The wording never changes. One coffee still reads 1 x Coffee, and a quantity of zero reads 0 x Coffee = 0p.
  • If the item name is empty the line still has both spaces around where it would have been, so it reads "2 x = 200p".
Code

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