// init array case some candidates receive no votes

Loop N from 0 to 5

RESULTS[N]=0

End loop

//main body

CALL FindWinningCount

CALL ProcessVotes

// output all votes

Loop N from 0 to 5

output NAMES[N] : "received ": RESULTS[N]

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

ProcessVotes

// HIGHSCORE=0

// HIGHSCOREPOS

// OVER50= 0

VOTES.resetNext() // start at beginning

loop while VOTES .hasNext() or OVER50 = 0

STUDENTVOTED = VOTES .getNext()

// 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

VOTES.resetNext() // start at beginning

loop while VOTES .hasNext()

TOTALNUMVOTES = TOTALNUMVOTES +1

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

// 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