DATA STRUCTURE /C++
Write a program that allows the user to enter the last names
offive candidates in a local election and the votes received by
each candidate. The program should then output each candidate’s
name, votes received by that candidate, 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 as
follows:
Candidate Johnson Miller
Duffy
Robinson Sam
Total
Votes Received 5000 4000 6000 2500 1800
19300
The Winner of the Election is Duffy.
#include <iostream>
using namespace std;
int main()
{
int winIndex =0;
int max=0;
int total;
string candiName[5];
int candiVotes[5];
for(int i=0;i<5;i++){
cout<<"Enter Candicate
"<<(i+1)<<" Name : ";
cin
>>candiName[i];
cout<<"Enter Candicate
"<<(i+1)<<" Votes : ";
cin
>>candiVotes[i];
cout<<"\n";
total += candiVotes[i];
if(max<candiVotes[i]){
max =
candiVotes[i];
winIndex = i;
}
}
cout<<"Total Votes Received by all:
"<<total<<endl;
cout<<"The Winner of the Election is
"<<candiName[winIndex]<<endl;
return 0;
}
Get Answers For Free
Most questions answered within 1 hours.