1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Pseudocode help

  1. Jan 25, 2012 #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.

    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")
    if (vote2 > vote 1) and (vote2 > vote3) and (vote2 > vote 4) then
    print("The winner is cand2 with vote2")
    if (vote3 > vote 1) and (vote3 > vote2) and (vote3 > vote 4) then
    print("The winner is cand3 with vote3")
    if (vote4 > vote 1) and (vote4 > vote2) and (vote4 > vote 3) then
    print("The winner is cand4 with vote3")

    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
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted