10Medium
0/3

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.

[3]

Data types and structures Questions

Practise Edexcel GCSE Computer Science Data types and structures with exam-style questions for GCSE Computer Science. 45 questions covering Primitive and structured data types, Using variables and constants, and Manipulating strings, matched to the Edexcel GCSE Computer Science (1CP2) specification and written in Paper 1 and Paper 2 style. Every question includes a full worked solution and mark scheme, so you can see where marks are awarded rather than just whether you got the answer right.

PreviousNext

Data types and structures Questions

  1. GCSE
  2. /Computer Science
  3. /Data types and structures