An algorithm is designed to display the names of the eight planets in our solar system in reverse order of their distance from the Sun (starting with Neptune at index 7 and ending with Mercury at index 0).
Figure 1 shows the pseudocode for this algorithm, which currently contains logical errors.
1 SUBROUTINE getPlanet(planets)
planets $\leftarrow$ ['Mercury', 'Venus', 'Earth',
2 'Mars', 'Jupiter', 'Saturn',
'Uranus', 'Neptune']
3 RETURN planets[pIdx]
4 ENDSUBROUTINE
5
6 FOR i $\leftarrow\,$ 8 TO 0 STEP 1
7 OUTPUT(getPlanet(i))
8 ENDFOR
Rewrite line 1 and line 6 from Figure 1 to make the algorithm work as intended.
Line 1:
Line 6:
131 exam-style questions on AQA GCSE Computer Science Structured programming and subroutines (procedures and functions). Each one has a worked solution and a mark scheme showing where the marks go.