At the design stage, a programmer writes pseudocode for a module that works out the cost of a family's tickets to a museum. The module must:
- input the number of adults and the number of children
- calculate the cost, where an adult ticket costs £12.50 and a child ticket costs £6.00
- take 10% off the cost if the cost is more than £50.00
- output the cost.
Write the pseudocode for this module.
Model answer
CONSTANT AdultPrice ← 12.50
CONSTANT ChildPrice ← 6.00
DECLARE Adults : INTEGER
DECLARE Children : INTEGER
DECLARE Cost : REAL
INPUT Adults
INPUT Children
Cost ← Adults * AdultPrice + Children * ChildPrice
IF Cost > 50.00
THEN
Cost ← Cost * 0.9
ENDIF
OUTPUT "Total cost: ", Cost
Explanation
The module follows input, process, output: input both numbers, calculate the cost, apply the discount only if the condition is met, then output. Multiplying by 0.9 takes off 10%; a common error is to subtract 10 instead of 10%.