Skip to the task
Layout
Back to classic view

You are looking at lesson 1. Your place is still Practice test 1, task 1: About.

HOMEWORKTask 20 of 21 · step 8: Homework: the receipt

Homework: the receipt

Two parts in the folder hw/01: a receipt checked by an autotest, and an algorithm with a Mermaid flowchart in ALGORITHM.md.

Checklist

  • Every task is one commit with a clear message.

The homework has two parts, both in the folder hw/01. They are already in your repository: you only fill in the files.

1. The receipt: hw/01/main.c

Write a program that prints exactly this text. It is also in the file hw/01/tests/expected.txt, which the test compares your output with:

================================
RECEIPT No. 1
Shop "Kampelis"
================================
Item	Qty	Price
Bread	1	1.20
Milk	2	1.98
Cheese	1	3.45
--------------------------------
Subtotal:	6.63
Discount:	10%
To pay:		5.97
================================
Receipt saved: C:\receipts\2026\1.txt
Thank you for shopping!
  • Between the columns there are tabs (\t), not spaces. The To pay: line has two, because To pay: is shorter than 8 characters.
  • Quotes, \, %: you use everything from step 5.
  • Every line, the last one too, ends with \n.

2. The algorithm: hw/01/ALGORITHM.md

The file describes the task: the cashier adds up the prices of all items, and if the total is over 5 €, gives a 10 % discount. In place of TODO write:

  • pseudocode with all three blocks: sequence, repetition (while there are items) and selection (if the total > 5);
  • a flowchart in Mermaid, in the same mermaid block. Shapes: ([...]) start and end, [...] an action, {...} a condition, [/.../] output.

The test checks only that no TODO is left and that there is a flowchart. The lecturer grades the content: are all three blocks there, does the flowchart match the pseudocode, are the shapes right. Open the file on GitHub and check that the flowchart is drawn, not shown as an error.

Tests

In CLion pick All CTest at the top and click ▶. While the receipt is wrong, the test shows the first line that differs:

=== hw01_receipt: FAILED ===
The output differs on line 5.
  expected: |Item\tQty\tPrice|
  got:      |Item  Qty  Price|
  (\t = tab, ~ = a space at the end of the line)

Here spaces were typed instead of tabs.

Handing in

Commit and push. In your GitHub repository's Actions tab open the latest run:

  • the Tests step shows the same test output as in CLion, but built on Linux with AddressSanitizer;
  • the Points step and the run's Summary show the homework points: HW 1 (Receipt): 10/10 ✓ when both tests pass.

A red cross means the code does not compile: open the Build step. Homework of later topics you haven't done yet doesn't turn CI red: it shows 0/10 (not done yet).