2-write a program that allows the usar to enter the last names of five candidate
ID: 3625445 • Letter: 2
Question
2-write a program that allows the usar to enter the last names of five candidates in a loce electoni and the number of votes received by each candidate the program should then output each candidates name the number of votes received , and the percentage of total votes by candidateYour program should also output the winner of the election . Asimple output is
candidate Votes Received # of total Votes
Jonson 5000 25.91
Miller 4000 20.73
Duffy 6000 31.09
Robinson 2500 12.95
Ashtony 1800 9.33
Total 19300
Explanation / Answer
please rate - thanks
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{string name[5];
int votes[5],total=0,i;
cout<<"Enter information for candidate ";
for(i=0;i<5;i++)
{cout<<"Name "<<i+1<<": ";
cin>>name[i];
cout<<"votes: ";
cin>>votes[i];
total+=votes[i];
}
cout<<"Name Votes Percent ";
for(i=0;i<5;i++)
cout<<setw(12)<<left<<name[i]<<" "<<votes[i]<<" "<<setprecision(2)<<fixed<<votes[i]/(double)total*100.<<endl;
cout<<"Total Votes: "<<total<<endl;
system("pause");
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.