Photo AI

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 icon

Question 8

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.png

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

Answer

  1. Initialize Variables

    • SET count TO 0
    • SET heaviest TO 0
    • SET lightest TO a very high number (e.g. 9999)
  2. Start Input Loop

    • WHILE TRUE DO
      • PROMPT user for the weight ("Enter the weight for the item, 0 to quit:")
      • READ weight
      • IF weight < 0 THEN
        • DISPLAY "Error. No negatives allowed"
      • ELSE IF weight = 0 THEN
        • BREAK the loop
      • ELSE
        • INCREMENT count by 1
        • IF weight > heaviest THEN
          • SET heaviest TO weight
        • IF weight < lightest THEN
          • SET lightest TO weight
    • END WHILE
  3. Output Results

    • DISPLAY "Heaviest = " + heaviest
    • DISPLAY "Lightest = " + lightest

Join the GCSE students using SimpleStudy...

97% of Students

Report Improved Results

98% of Students

Recommend to friends

100,000+

Students Supported

1 Million+

Questions answered

;