subject

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.

ansver
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 01:00, joedawg50
What is added to the < meta > tag to describe the encoding type?
Answers: 1
image
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
image
Computers and Technology, 23.06.2019 14:00, ava5015
What is html ? give a small description about html
Answers: 2
image
Computers and Technology, 23.06.2019 15:00, Siris420
Plz ( which is an example of a good url?
Answers: 1
You know the right answer?
Write a program that allows the user to enter the last names of five candidates in a local election...

Questions in other subjects:

Konu
English, 04.12.2020 05:50