I need assistance with Voting Poll Program

Suppose a new member of the city council has to be chosen from three candidates and suppose there are 4 voting stations. We need a C++ program that will count the votes for every candidate and display the result. At every voting station the voters have to be asked one after the other for which candidate (indicated by A or B or C) he or she wants to vote. X is entered when all the voters at the specific voting station have voted.

The program has the following structure:
· The three totals and the number of spoilt votes are initialised to 0.
· Now a for loop follows, going from 1 to the number of voting stations.
· Inside this loop is a while loop. A prompting message appears on the screen, asking the voter for which candidate he or she wants to vote. The choice of the voter is then input.
· Inside the while loop is a switch statement to increment the correct total. The default option is used to count the number of spoilt votes.
· The while loop is exited when X is entered for the choice.
· When the for loop is exited, the three totals and the number of spoilt votes are displayed.


this is what i did already and i feel lost:

#include <iostream>
using namespace std;
int main( )
{
const int NR_VOTING_STATIONS = 4;
int votesForA, votesForB, votesForC, spoiltVotes;
char vote;
// initialise totals
// loop over the voting stations
for (votesForA = 0; votesForA = 'A'; spoiltVotes++)
{
for (votesForB = 0; votesForB = 'B'; spoiltVotes++)
{
for (votesForC = 0; votesForB = 'C'; spoiltVotes++)
{
cout << "Which candidate do you want to choose: ";
cin >> vote "\n";
{

}

}
}
// loop over voters
while (votesForA != 'A') && (votesForB != 'B') && (votesForC != 'C')
{
cout <<"Enter which candidate you want :";
cin >> vote;
//complete the loop
}
switch (vote)
{
case 'A' :
cout << "A";
case 'B' :
cout << "B";
case 'C' :
cout << "C";
cout<< endl;
default:
case 'X' :
cout << "Spoilt Votes" << endl;
}
// display results
cout << endl << endl;
cout << "Total candidate A: " << votesForA << endl;
cout << "Total candidate B: " << votesForB << endl;
cout << "Total candidate C: " << votesForC << endl;
cout << "Total spoilt votes: " << spoiltVotes << endl;
return 0;
}
Last edited on
Topic archived. No new replies allowed.