Write a program that allows the user to enter the last names of five candidates in a local election and the number of votes received by each candidate. The program should then output each candidate's name, the number of votes received, and the percentage of the total votes received by the candidate. Your program should also output the winner of the election. A sample output is:
Candidate
Votes
Received
Percent of Total Votes
Jack
52
26
Jill
41
20.5
Bob
13
6.5
Bill
74
37
Sam
20
10
Total
200
The election winner is Bill.
#include<iostream>
#include<iomanip>
#include<vector>
using namespace std;
int main()
{
vector<string> name;
vector<int> votes;
// store the total no of votes
int total_votes = 0;
// store the maximum no of votes
int max = INT_MIN;
int i;
for( i = 0 ; i < 5 ; i++ )
{
string str;
cout<<"Enter name : ";
cin>>str;
// add name to vector
name.push_back(str);
int x;
cout<<"Enter votes recieved : ";
cin>>x;
// add votes to vector
votes.push_back(x);
total_votes += x;
if( x > max )
max = x;
}
cout<<setw(20)<<"Candidate"<<" ";
cout<<setw(20)<<"Votes Received"<<" ";
cout<<setw(20)<<"% of Total Votes"<<endl;
for( i = 0 ; i < votes.size() ; i++ )
{
// calculate percentage of votes recieved
double per = (double)votes[i] / (double)total_votes * 100.0;
cout<<setw(20)<<name[i]<<" ";
cout<<setw(20)<<votes[i]<<" ";
cout<<setw(20)<<per<<endl;
}
cout<<"Total : "<<total_votes;
cout<<"\nWinners are : ";
for( i = 0 ; i < votes.size() ; i++ )
if( votes[i] == max )
cout<<name[i]<<" ";
return 0;
}
Sample Output

Write a program that allows the user to enter the last names of five candidates in...