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

C++ ONLY PLEASE, I HAVE RECEIVED MULTIPLE REPLY\'S BUT NONE OF THEM WORK.HAS ANY

ID: 3677375 • Letter: C

Question

 C++ ONLY PLEASE, I HAVE RECEIVED MULTIPLE REPLY'S BUT NONE OF THEM WORK.HAS ANYONE ACTUALLY FIGURED THIS ONE OUT? PLEASE HELP!!  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 Johnson          5000             25.91 Miller           4000             20.73 Duffy            6000             31.09 Robinson         2500             12.95 Ashtony          1800              9.33 Total            19300 The Winner of the Election is Duffy.  #include <iostream> using namespace std;  int sumVotes(int list[], int size); int winnerIndex(int list[], int size);  int main() {     /* Type your code here. */     return 0; } 

Explanation / Answer

#include <iostream>
using namespace std;

int sumVotes(int list[], int size){
   int sum = 0;
   for(int i = 0; i < size; i++){
       sum += list[i];
   }
   return sum;
}
int winnerIndex(int list[], int size){
   int max = 0;
   for(int i = 1; i < size; i++){
       if(list[max] < list[i]) max = i;
   }
return max;
}

int main() {

   /* Type your code here. */
   string lastName[5];
   int votes[5];
   for(int i = 0; i < 5; i++){
       cout << "Enter the last name for candidate " << i + 1 << ": ";
       cin >> lastName[i];
       cout << "Enter the number of votes for candidate " << i + 1 << ": ";
       cin >> votes[i];
   }
   int total = sumVotes(votes, 5);
   cout << "Candidate Votes Received % of Total Votes ";
   for(int i = 0; i < 5; i++){
       cout << lastName[i] << " " << votes[i] << " " << votes[i] * 100.0 / total << " ";
   }
   int index = winnerIndex(votes, 5);
   cout << "The Winner of the Election is " << lastName[index];

   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote