Pseudocode help

  1. 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 succesful 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?
     
  2. jcsd
Know someone interested in this topic? Share a link to this question via email, Google+, Twitter, or Facebook

Have something to add?

0
Draft saved Draft deleted