Question

DATA STRUCTURE /C++ Write a program that allows the user to enter the last names offive...

DATA STRUCTURE /C++

Write a program that allows the user to enter the last names offive candidates in a local election and the votes received by each candidate. The program should then output each candidate’s name, votes received by that candidate, 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 as follows:
Candidate Johnson Miller
Duffy
Robinson Sam
Total
Votes Received 5000 4000 6000 2500 1800
19300
The Winner of the Election is Duffy.

Homework Answers

Answer #1

#include <iostream>

using namespace std;

int main()
{
   int winIndex =0;
   int max=0;
   int total;
   string candiName[5];
   int candiVotes[5];
   for(int i=0;i<5;i++){
       cout<<"Enter Candicate "<<(i+1)<<" Name : ";
       cin >>candiName[i];
       cout<<"Enter Candicate "<<(i+1)<<" Votes : ";
       cin >>candiVotes[i];
       cout<<"\n";
       total += candiVotes[i];
       if(max<candiVotes[i]){
           max = candiVotes[i];
           winIndex = i;
       }
   }
   cout<<"Total Votes Received by all: "<<total<<endl;
   cout<<"The Winner of the Election is "<<candiName[winIndex]<<endl;
   return 0;
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions