Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please answer in C++(simple as possible please), Explain code with comments, and

ID: 3761988 • Letter: P

Question

Please answer in C++(simple as possible please), Explain code with comments, and make sure it compiles please. Thankyou!

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. A sample output is: Candidate Votes Received % of Total Votes The Winner of the Election is Duffy.

Explanation / Answer

#include <iostream.h>
#include<iomanip.h>
#include<string.h>

using namespace std;

int main()
{

//Parallel Array
int votes[50];
string candidate[50];
double percent[50];

int sum;
int counter;
int index;
int largestscale;
int x;
int i;

cout << "Enter in the Candidate's name *Hit SPACE* Then enter the votes" << endl;
counter = 0;

for (counter = 0; counter < 5; counter++)
{
cin >> candidate[counter];
cin >> votes[counter];

}
      

sum = 0;
for (i = 0; i < 5; i++)
{
   sum = sum + votes[i]; //finds the sum

}
cout << "Total number of votes is" << sum << endl;
for (x = 0; x < 5; x++)
{
percent[x] = (votes[x] / sum) * 100; //<---I'm guessing my main problem is somewhere here?
}

   //Finds the largest number of votes in the array
   int maxIndex = 0;
   for (index = 0; index < 5; index++)
   {
       if (votes[maxIndex] < votes[index])
           maxIndex = index;
   largestscale = votes[maxIndex];
   }

//Begin of output.
   cout << "Candidate" << " " << "# of votes" << "" << "Percent of vote" << endl;
for (counter =0; counter < 5; counter++)
{
  
   cout << candidate[counter] << votes[counter] << percent[counter] << endl;
}
cout <<"The winner is" << candidate[largestscale] << endl;

cin.ignore().get();
return 0;
   }