An election is contested by 5 candidates. The candidates are numbered 1 to 5 and the voting is done by marking the candidate number on the ballot paper. Write a program to read the ballots and count the votes cast for each candidate. Create custom exception to find invalid age of voter
The Answer to the Question
is below this banner.
Can't find a solution anywhere?
NEED A FAST ANSWER TO ANY QUESTION OR ASSIGNMENT?
Get the Answers Now!You will get a detailed answer to your question or assignment in the shortest time possible.
Here's the Solution to this Question
#include <iostream>
#include <string>
using namespace std;
void Menu()
{
cout << "\nA - first candidate"
<< "\nB - second candidate"
<< "\nC - third candidate"
<< "\nD - fourth candidate"
<< "\nE - fifth candidate"
<< "\n0 - exit program" << endl;
cout << "Your choice: ";
}
int main()
{
char ch;
int candidates[5] = {0,0,0,0,0};
do
{
Menu();
cin >> ch;
switch (ch)
{
case 'A':case 'a':
{
candidates[0]++;
break;
}
case 'B':case 'b':
{
candidates[1]++;
break;
}
case 'C':case 'c':
{
candidates[2]++;
break;
}
case 'D':case 'd':
{
candidates[3]++;
break;
}
case 'E':case 'e':
{
candidates[4]++;
break;
}
}
} while (ch != '0');
cout << "\nResults of votes:";
cout << "\nFirst candidate " << candidates[0]
<< "\nSecond candidate " << candidates[1]
<< "\nThird candidate " << candidates[2]
<< "\nFourth candidate " << candidates[3]
<< "\nFifth candidate " << candidates[4];
}