An online retailer uses a program to calculate the delivery costs and final total at checkout.
The pseudocode for the algorithm is shown below. The items SHIPPING_RATE and FREE_SHIPPING_THRESHOLD are constants.
1 CONST REAL SHIPPING_RATE
2 SET SHIPPING_RATE TO 4.99
3 CONST REAL FREE_SHIPPING_THRESHOLD
4 SET FREE_SHIPPING_THRESHOLD TO 45.00
5
6 SEND "Welcome to the checkout system" TO DISPLAY
7 SEND "Enter order total cost:" TO DISPLAY
8 RECEIVE orderTotal FROM (REAL) KEYBOARD
9
10 IF orderTotal < FREE_SHIPPING_THRESHOLD THEN
11 SET deliveryCharge TO SHIPPING_RATE
12 ELSE
13 SET deliveryCharge TO 0.0
14 ENDIF
15
16 SET finalTotal TO orderTotal + deliveryCharge
17 SEND "Shipping Cost: " & deliveryCharge TO DISPLAY
18 SEND "Total Amount Due: " & finalTotal TO DISPLAY
Explain why it is good programming practice to define values as constants, rather than using fixed literal values (like 4.99 or 45.00) directly within the code.
44 exam-style questions on Edexcel GCSE Computer Science Data types and structures, covering Primitive and structured data types, Using variables and constants, and Manipulating strings. Each one has a worked solution and a mark scheme showing where the marks go.