P-Cubed wants to know the weight of the heaviest item and the weight of the lightest item - Edexcel - GCSE Computer Science - Question 8 - 2018 - Paper 1
Question 8
P-Cubed wants to know the weight of the heaviest item and the weight of the lightest item.
An operator enters weights for each item. The operator enters 0 when fini... show full transcript
Worked Solution & Example Answer:P-Cubed wants to know the weight of the heaviest item and the weight of the lightest item - Edexcel - GCSE Computer Science - Question 8 - 2018 - Paper 1
Step 1
Write an algorithm to meet the requirements.
96%
114 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
SET count TO 0
SET heaviest TO 0
SET lightest TO Infinity
REPEAT UNTIL weight IS 0:
a. DISPLAY "Enter the weight for the item, 0 to quit:"
b. READ weight FROM INPUT
c. IF weight < 0 THEN
i. DISPLAY "Error. No negatives allowed"
ii. CONTINUE TO NEXT ITERATION
d. IF weight > heaviest THEN
i. SET heaviest TO weight
e. IF weight < lightest AND weight > 0 THEN
i. SET lightest TO weight
f. INCREMENT count BY 1