Skip to content
MathsGenie logo
Open app

Course home

  1. IGCSE
  2. Computer Science Edexcel
  3. Question bank

Algorithms

EasyMedium
123456789101112131415161718192021222324252627
Question 8

An analyst is writing an algorithm to track fruit inventory at a local orchard market. They have created a draft algorithm to count apples and pears, as well as calculate the total weight of pears collected (assuming each pear weighs approximately 150 grams).

1 SET Item TO ""
2 SET TotalQuantity TO 0
3 SET AppleCount TO 0
4 SET PearCount TO 0
5 SET PearWeight TO 0
6
7 WHILE Item <> "QUIT" DO
8     RECEIVE Item FROM (STRING) KEYBOARD
9     IF Item = "Apple" THEN
10        SET AppleCount TO AppleCount + 1
11    ELSE
12        IF Item = "Pear" THEN
13            SET PearCount TO PearCount + 1
14            SET PearWeight TO PearWeight + 150
15        END IF
16    END IF
17 END WHILE
18
19 SET TotalQuantity TO AppleCount + PearCount
20
21 SEND ("Total pieces of fruit: " & TotalQuantity) TO DISPLAY
22 SEND ("Number of apples: " & AppleCount) TO DISPLAY
23 SEND ("Total weight of pears (g): " & PearCount) TO DISPLAY

Give the line number of the pseudocode that contains the logic error.

[1]

Algorithms Questions

  1. IGCSE
  2. /Computer Science
  3. /Algorithms