## Pascal

Moderators: None (Apply to moderate this forum)
Number of posts: 14004

This Forum Only

code problem Posted by adamantium on 22 Nov 2004 at 2:00 PM
I'm a newbie and need some help desperately!!!
My question goes like this:

A company is voting for a chairmen and is recorded by entering the numbers 1 to 5 depending on which of the five candidates secured a vote. Enter 0 toindicate that all votes have been input. It must print how many votes for each candidate. Once all the votes have
been entered, print the total for each candidate and the total of all the valid votes.

I need some help with the control statements, I don't really know how to code them properly.
Thank you
Re: code problem Posted by zibadian on 22 Nov 2004 at 4:30 PM
: I'm a newbie and need some help desperately!!!
: My question goes like this:
:
: A company is voting for a chairmen and is recorded by entering the numbers 1 to 5 depending on which of the five candidates secured a vote. Enter 0 toindicate that all votes have been input. It must print how many votes for each candidate. Once all the votes have
: been entered, print the total for each candidate and the total of all the valid votes.
:
: I need some help with the control statements, I don't really know how to code them properly.
: Thank you
:
The best way to do this is to create an NumberOfVotes array with 5 elements, one for each candidate.
Then if someone inputs a vote, increase that number by 1, like so:
if CastVote > 0 then

Around this simple setup you can then create a repeat-until loop to keep on voting until some-one casts a vote on candidate 0.
Writing the number of votes for each candidate is simply a for-do loop with a writeln() statement and the NumberOfVotes array.
Re: code problem Posted by adamantium on 23 Nov 2004 at 4:16 AM
: : I'm a newbie and need some help desperately!!!
: : My question goes like this:
: :
: : A company is voting for a chairmen and is recorded by entering the numbers 1 to 5 depending on which of the five candidates secured a vote. Enter 0 toindicate that all votes have been input. It must print how many votes for each candidate. Once all the votes have
: : been entered, print the total for each candidate and the total of all the valid votes.
: :
: : I need some help with the control statements, I don't really know how to code them properly.
: : Thank you
: :
: The best way to do this is to create an NumberOfVotes array with 5 elements, one for each candidate.
: Then if someone inputs a vote, increase that number by 1, like so:
:
:     if CastVote > 0 then
:

: Around this simple setup you can then create a repeat-until loop to keep on voting until some-one casts a vote on candidate 0.
: Writing the number of votes for each candidate is simply a for-do loop with a writeln() statement and the NumberOfVotes array.
:
Thanks I get it now it makes sense. But the problem is I don't want to use an array so I guess i'll try to work around it. But thanks!
Re: code problem Posted by adamantium on 23 Nov 2004 at 2:59 PM
: : I'm a newbie and need some help desperately!!!
: : My question goes like this:
: :
: : A company is voting for a chairmen and is recorded by entering the numbers 1 to 5 depending on which of the five candidates secured a vote. Enter 0 toindicate that all votes have been input. It must print how many votes for each candidate. Once all the votes have
: : been entered, print the total for each candidate and the total of all the valid votes.
: :
: : I need some help with the control statements, I don't really know how to code them properly.
: : Thank you
: :
: The best way to do this is to create an NumberOfVotes array with 5 elements, one for each candidate.
: Then if someone inputs a vote, increase that number by 1, like so:
:
:     if CastVote > 0 then
:

: Around this simple setup you can then create a repeat-until loop to keep on voting until some-one casts a vote on candidate 0.
: Writing the number of votes for each candidate is simply a for-do loop with a writeln() statement and the NumberOfVotes array.
:
Can anyone show me how to fix this without using arrays. I need a very simple method.
Thank you
Re: code problem Posted by zibadian on 23 Nov 2004 at 3:52 PM
: : : I'm a newbie and need some help desperately!!!
: : : My question goes like this:
: : :
: : : A company is voting for a chairmen and is recorded by entering the numbers 1 to 5 depending on which of the five candidates secured a vote. Enter 0 toindicate that all votes have been input. It must print how many votes for each candidate. Once all the votes have
: : : been entered, print the total for each candidate and the total of all the valid votes.
: : :
: : : I need some help with the control statements, I don't really know how to code them properly.
: : : Thank you
: : :
: : The best way to do this is to create an NumberOfVotes array with 5 elements, one for each candidate.
: : Then if someone inputs a vote, increase that number by 1, like so:
: :
: :     if CastVote > 0 then
: :

: : Around this simple setup you can then create a repeat-until loop to keep on voting until some-one casts a vote on candidate 0.
: : Writing the number of votes for each candidate is simply a for-do loop with a writeln() statement and the NumberOfVotes array.
: :
: Can anyone show me how to fix this without using arrays. I need a very simple method.
: Thank you
:
You can use 5 variables with an if-then-else statement like this:
if CastVote = 1 then
Candidate1 := Candidate1 + 1
else if CastVote = 2 then
Candidate2 := Candidate2 + 1
else if CastVote = 3 then
Candidate3 := Candidate3 + 1
{etc.}

The rest stays pretty much the same way.

## Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic