- Home >
- Programming >
- trinbarjam national election
trinbarjam national election
Question Description
The clue is often in the question. Pseudo code is plain Engligh used to describe a set of steps (objectives) required to do something. For example, if we take your spec. and break it down into objectives...
1. determine the winning candidate for a constituency in the national elections
2. accept as input the names of the four candidates and the number of votes each candidate receives. (The successful candidate is the one who received the most votes.)
3. Print the name of the winner and the number of votes he/she received.
...and then check the order of objectives: it's pretty logical that we need to know candidate names and how many votes before we can find a winner, and we need to know who the winner is before we can output the winner name and votes. - So our list of objectives becomes...
1. accept as input the names of the four candidates and the number of votes each candidate receives. (The successful candidate is the one who received the most votes.)
2. determine the winning candidate for a constituency in the national elections
3. Print the name of the winner and the number of votes he/she received.
...Finally, we need to convert each objective into pseudo code; just break each objective down into smaller steps.
{required variables}
define a variable array of strings for candidate names
define a variable array of whole numbers for candidate votes
define a single string variable for the winner
define a general purpose counter "i" for loops in code
define a general max variable number to hold highest number of votes
{1. accept as input the names of the four candidates and the number of votes each candidate receives. (The successful candidate is the one who received the most votes.)}
start a loop setting "i" from 1 to 4
write text to screen "enter candidate name: "
read candidate name
write text to screen "enter number of votes for <candidate name>: "
read number of votes
next loop
{2. determine the winning candidate for a constituency in the national elections}
set winner equal to the first candidates name
set max equal to the first candidates votes
start a loop setting "i" from 2 to 4
if candidate "i" votes greater than max then
set max equal to that candidates votes
set winner variable equal to that candidates name
next loop
{3. Print the name of the winner and the number of votes he/she received.}
write text to screen "the winner was <winneIMG-20160227-WA0006.jpgr> with <max> votes"
exit the program
This question has not been answered.
Create a free account to get help with this and any other question!
Similar Content
2001 A Space Odyssey
by Arthur Clarke
The Elegant Universe
by Brian Greene
All the Kings Men
by Robert Penn Warren
Oliver Twist
by Charles Dickens
The Remains Of The Day
by Kazuo Ishiguro
Orphan Train
by Christina Baker Kline
The House of the Seven Gables
by Nathaniel Hawthorne
The 48 Laws of Power
by Robert Greene
Fast Food Nation
by Eric Schlosser
Studypool values your privacy. Only questions posted as Public are visible on our website.
Brown University
1271 Tutors
California Institute of Technology
2131 Tutors
Carnegie Mellon University
982 Tutors
Columbia University
1256 Tutors
Dartmouth University
2113 Tutors
Emory University
2279 Tutors
Harvard University
599 Tutors
Massachusetts Institute of Technology
2319 Tutors
New York University
1645 Tutors
Notre Dam University
1911 Tutors
Oklahoma University
2122 Tutors
Pennsylvania State University
932 Tutors
Princeton University
1211 Tutors
Stanford University
983 Tutors
University of California
1282 Tutors
Oxford University
123 Tutors
Yale University
2325 Tutors