Computers and Technology, 28.05.2021 14:00 romeroalexis817
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.
i have this
#include
#include
#include
using namespace std;
int findMax(int votes[]);
void main()
{
int votes[20];
string name[10];
int total=0;
float percent[10];
int m, i, loc;
cout<<"Enter the names of candidates in local election and number of votes:"<
for(int i=0;i<5;i++)
{
cin>>name[i];
cin>>votes[i];
}
for(i=0;i<5;i++)
{
total=total+votes[i];
}
for(i=0;i<5;i++)
{
percent[i]=((votes[i]/total)*100);< br />
}
cout<<"Candidate"<<'\t' <<"VotesReceived"<<'\t' <<"% of Total Votes"<
cout<
for(i=0;i<5;i++)
{
cout<
}
cout<<"Total:"<
m=findMax(votes);
cout<<"Winner of the election is"<
system("pause");
}
int findMax(int votes[])
{
int i, max, loc;
max=votes[0];
for(i=1;i<5;i++)
{
if(votes[i]>max)
{
max=votes[i];
loc=i;
}
}
return loc;
}
But, it is saying that loc is not initialized, and it is also not calculating % of total votes or the winner of the election and I don't what to do to fix it.
Answers: 1
Computers and Technology, 22.06.2019 13:30, morganwendel126
Use the keyword strategy to remember the meaning of the following word. the meaning for the word has been provided. write your keyword and describe the picture you would create in your mind. centurion: a commander in the army of ancient rome. keyword: picture:
Answers: 2
Write a program that allows the user to enter the last names of five candidates in a local election...
Mathematics, 04.12.2020 05:50
Chemistry, 04.12.2020 05:50
Biology, 04.12.2020 05:50
Mathematics, 04.12.2020 05:50
English, 04.12.2020 05:50