WSU student government is getting ready to conduct its annual elections and need
ID: 3682776 • Letter: W
Question
WSU student government is getting ready to conduct its annual elections and needs your help. The organizers ask you to write a program that will allow them to enter the last names of the five contesting candidates, and the number of votes received by each candidate. The program should then outputs the name of each candidate, number of total votes, and the percentage of the total votes received by the candidate. Then your program should declare the winner based on the results. Grading scheme: calculate the total votes -5 points; the percentage of the total votes received by the candidate. - 5 points; main function - 5 points, declare the winner based on the results- 5 pointsExplanation / Answer
#include <iostream>
#include <string.h>
using namespace std;
int main ()
{
int i;
string names[5];
int votes[5];
int sum = 0,max = 0,winner = -1;
for(i=0;i<5;i++)
{
cout<<"Enter last name of candidate "<<i+1<<": ";
cin>>names[i];
cout<<"Enter votes he received: ";
cin>>votes[i];
sum += votes[i];
if(max<votes[i])
{
max = votes[i];
winner = i;
}
}
cout<<" Name of cadidates are: ";
for(i=0;i<5;i++)
cout<<names[i]<<" ";
cout<<" Total votes received = "<<sum<<endl;
cout<<" Percentage of votes received by each candi ";
for(i=0;i<5;i++)
cout<<names[i]<<" "<<votes[i]*100.00/sum<<endl;
cout<<"Winner of election is "<<names[winner]<<" with "<<max<<" number of votes ";
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.