Determining Winning Candidate in National Election

  • Thread starter lionely
  • Start date
In summary, the algorithm uses a while loop to determine the winning candidate for a constituency in the national elections. It accepts the names of four candidates and their corresponding votes as input, and then compares the votes to determine the candidate with the most votes. It uses a variable to keep track of the winning candidate and their votes, and outputs the name and number of votes for the winner. The algorithm ends when all votes have been entered.
  • #1
lionely
576
2
Develop an algorithim or write pseudocode to determine the winning candidate for a constiuency in the national elections. The algorithim must accept as input the names of the four candiddates and the number of votes each candidate receives. The successful candidate is one who receieved the most votes.
Print the name of the winner and the number of votes he/she receieved.
Design and execute a trace table that accepts vote data at a polling station in a constiituency. Data should include special votes,general(valid) votes and spoilt votes. Votes should be cast for anyone of four parties, DAP,WNA,UPM or PDR. The table should trace the increment of each vote category and determine which party secured the majority of votes. The table should have at least ten iterations and should end when a specific value is entered.

ATTEMPT
START
Declare: winning_cand,cand1,cand2,cand3,cand4 ---> string
vote1,vote2,vote3,vote4,winning_vote----> integer
Print("enter four names")
read cand1,cand2,cand3,cand4
Print("enter number of votes")
read vote1,vote2,vote3,vote4

if (vote1 > vote 2) and (vote1 > vote3) and (vote1 > vote 4) then
print("The winner is cand1 with vote1")
else
if (vote2 > vote 1) and (vote2 > vote3) and (vote2 > vote 4) then
print("The winner is cand2 with vote2")
else
if (vote3 > vote 1) and (vote3 > vote2) and (vote3 > vote 4) then
print("The winner is cand3 with vote3")
else
if (vote4 > vote 1) and (vote4 > vote2) and (vote4 > vote 3) then
print("The winner is cand4 with vote3")
endif
endif
endif
endif
STOP

My teacher said my pseudocode was wrong and I should use a while loop, and I think I need more variables , could someone please assist me?
 
Physics news on Phys.org
  • #2
STARTDeclare: winning_cand,cand1,cand2,cand3,cand4 ---> stringvote1,vote2,vote3,vote4,winning_vote----> integerPrint("enter four names")read cand1,cand2,cand3,cand4Print("enter number of votes")read vote1,vote2,vote3,vote4Set winning_cand = " "Set winning_vote = 0While (vote1 > 0) or (vote2 > 0) or (vote3 > 0) or (vote4 > 0) if (vote1 > 0) and (vote1 > winning_vote) then set winning_cand = cand1 set winning_vote = vote1 endif if (vote2 > 0) and (vote2 > winning_vote) then set winning_cand = cand2 set winning_vote = vote2 endif if (vote3 > 0) and (vote3 > winning_vote) then set winning_cand = cand3 set winning_vote = vote3 endif if (vote4 > 0) and (vote4 > winning_vote) then set winning_cand = cand4 set winning_vote = vote4 endifEnd Whileprint("The winner is" + winning_cand + "with" + winning_vote + "votes") STOP
 

1. How is the winning candidate determined in a national election?

The winning candidate in a national election is determined by the number of electoral votes they receive. Each state has a certain number of electoral votes based on their population, and the candidate who wins the majority of the electoral votes (270 or more) becomes the winner of the election.

2. Can the popular vote determine the winner of a national election?

In most cases, the popular vote does not directly determine the winner of a national election. However, there have been instances where the winner of the popular vote did not win the election due to the electoral college system. The popular vote can still influence the outcome of the election by showing the overall support for a candidate.

3. How are the electoral votes allocated to each state?

The number of electoral votes allocated to each state is based on its representation in Congress. Each state has a certain number of representatives in the House of Representatives and two senators, which adds up to their total number of electoral votes. The District of Columbia also receives three electoral votes.

4. What happens if no candidate receives a majority of the electoral votes?

If no candidate receives a majority of the electoral votes, the House of Representatives chooses the president from the top three candidates. Each state delegation gets one vote, and the candidate who receives a majority of the state votes (26 or more) becomes the president. The vice president is chosen by the Senate from the top two candidates.

5. Can the results of a national election be challenged or overturned?

In rare cases, the results of a national election can be challenged or overturned. This can happen if there are allegations of election fraud or if there are discrepancies in the vote counts. The decision to challenge or overturn an election is made by the courts, and the process can be lengthy and complex.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
26
Views
5K
Back
Top