Register to reply

Pseudocode help

by lionely
Tags: pseudocode
Share this thread:
lionely
#1
Jan25-12, 03:10 PM
P: 523
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?
Phys.Org News Partner Science news on Phys.org
Suddenly, the sun is eerily quiet: Where did the sunspots go?
'Moral victories' might spare you from losing again
Mammoth and mastodon behavior was less roam, more stay at home

Register to reply

Related Discussions
Pseudocode help Engineering, Comp Sci, & Technology Homework 26
Need a little help with pseudocode Engineering, Comp Sci, & Technology Homework 4
Pseudocode help Engineering, Comp Sci, & Technology Homework 45
Pseudocode Help Engineering, Comp Sci, & Technology Homework 1