# Example Solution Pseudo Code

Loop N from 0 to 5
RESULTS[N]=0
End loop

//main body

CALL FindWinningCount
Loop N from 0 to 5
end loop

If OVER50 then
Output "winner is : NAMES[HIGHSCOREPOS]
else
// output 2 with highest votes for next round
CALL FindOtherCandidate
Output NAMES[HIGHSCOREPOS] " and " NAMES[HIGHSCOREPOS2] " Will proceed to next round
end if

// end main body

// sub process votes and store highest and maybe winner
// HIGHSCORE=0
// HIGHSCOREPOS
// OVER50= 0

loop while VOTES .hasNext() or OVER50 = 0

// store votes in array results need convert candidate number to pos in array so reduce by 1
RESULTS [STUDENTVOTED-1] = RESULTS [STUDENTVOTED-1] + 1
If RESULTS [STUDENTVOTED-1] > HIGHSCORE
HIGHSCOREPOS = STUDENTVOTED-1
HIGHSCORE = RESULTS [STUDENTVOTED-1]
end if
If RESULTS [STUDENTVOTED-1] > HALFVOTES then
OVEVER50 = 1
end if

end loop

// sub to count the total number of students that voted so can check for winner

FindWinningCount
end loop
// find number to win
HALFVOTES = TOTALNUMVOTES / 2 // assume can we use standard operators

// find the second candidate
FindOtherCandidate
HIGHSCOREPOS2 = 0
Loop N from 0 to 5
SCORE = RESULTS[N]
If SCORE > HIGHSCOREPOS2 and N ≠ HIGHSCOREPOS then
HIGHSCOREPOS2 = N
HIGHSCORE2 = SCORE
end if
end loop

Scroll to Top