172k views
5 votes
Develop an algorithm to print the names of the candidates who should receive a refund. A refund is due if the candidate’s votes received equals or exceeds 20 per cent of the votes cast in the constituency. The algorithm should also determine and print the number of candidates who received a refund. Test the algorithm with data from ten candidates. The algorithm must accept as input the names of the candidates, votes received and the votes cast in the constituency. The algorithm should print the name of the candidate and the words “Refund Due” or “No Refund” and the number of candidates who received a refund.

User Hazhir
by
9.1k points

1 Answer

6 votes

Answer:

PROCEDURE calculate_refund(candidates, votes_received, votes_cast)

refund_due = 0

FOR i = 0 TO LENGTH(candidates) - 1

IF votes_received[i] >= 0.2 * votes_cast

PRINT candidates[i] + " Refund Due"

refund_due = refund_due + 1

ELSE

PRINT candidates[i] + " No Refund"

END IF

END FOR

PRINT "Number of candidates who received a refund: " + refund_due

END PROCEDURE

Step-by-step explanation:

This algorithm takes as input the names of the candidates, the votes received, and the votes cast in the constituency. It loops through each candidate, and if the number of votes received for that candidate is equal to or greater than 20% of the votes cast in the constituency, it prints the candidate name and "Refund Due". If the number of votes received is less than 20% of the votes cast, it prints the candidate name and "No Refund". Finally, the algorithm prints the number of candidates who received a refund.

User Dylants
by
7.7k points