The following pseudocode uses a subprogram to calculate and display a tax receipt.
1 SET receiptHeader TO "--- PRE-CHECK ---"
2
3 PROCEDURE printReceipt ( itemCost, taxRate )
4 BEGIN PROCEDURE
5 SET receiptHeader TO "--- TAX INVOICE ---"
6
7 # calculate tax amount
8 SET taxAmount TO itemCost * taxRate
9
10 # calculate total price
11 SET totalPrice TO itemCost + taxAmount
12
13 # print receipt details
14 SEND receiptHeader TO DISPLAY
15 SEND "Item Price: " & itemCost TO DISPLAY
16 SEND "Tax Amount: " & taxAmount TO DISPLAY
17 SEND "Total: " & totalPrice TO DISPLAY
18 END PROCEDURE
19
20 SEND receiptHeader TO DISPLAY
21 SEND "Enter item cost:" TO DISPLAY
22 RECEIVE cost FROM (REAL) KEYBOARD
23 SEND "Enter tax rate:" TO DISPLAY
24 RECEIVE tax FROM (REAL) KEYBOARD
25 CALL printReceipt(cost, tax)
Explain how the correct value for the variable receiptHeader is chosen on line 14.
29 exam-style questions on Edexcel GCSE Computer Science Subprograms, covering Built-in and user-devised subprograms, Functions versus procedures, and Global and local variables. Each one has a worked solution and a mark scheme showing where the marks go.