Selection
A class of 30 students have taken four tests each. The teacher wants to decide on which students need to take a further test based on their results. A student will retake the test if their average score is less than 50%. The results should display all of the students who need to retake.
Finally the last step is to add selection. At this point it should be fairly obvious what needs to be done. Although we have done variables → iteration → selection there is no reason why you can not change the order. At the end of the day this guide is just here to help you through the logic of coding not give you a magic formula.
We need to test the percentage to see if it is less than 50. This leads us to the following statement -
IF percentage < 50 THEN
PRINT students[count].name
END IF
putting it together gives us
FOR count =0 TO students.length -1
total = 0
FOR j = 0 to students[count].scores.length -1
total = total + students[count].scores[j]
NEXT
average = total /4
percentage = 10 * average
IF percentage < 50 THEN
PRINT students[count].name
END IF
NEXT