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
Write a program that allows the user to enter the last names of five candidates in...
Write a program that allows the user to enter the last names of five 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 Votes Received 5000 4000 6000 2500 1800 19300...
C++ please Write a program that allows a user to enter any number of product prices...
C++ please Write a program that allows a user to enter any number of product prices and show the total of all of the products. Use 0.00 as a sentinel value. (while loop)
Create a program that allows the user to input a list of first names into one...
Create a program that allows the user to input a list of first names into one array and last names into a parallel array. Input should be terminated when the user enters a sentinel character. The output should be a list of emial addresses where the address is of the following form: [email protected] Declare FirstName[100] as String Declare LastName[100] as String Declare email as String Declare K as Integer Declare index as Integer Write "Enter first and last name." Write...
1.Write pseudocode for a program that allows the user to input two numbers (X and Y)...
1.Write pseudocode for a program that allows the user to input two numbers (X and Y) and a code C. If the code has value 1, the program should output the larger of X and Y and otherwise output the smaller. Now convert your pseudocode to an assembly language program. Enter the program into the lab software assembler. Assemble the program and execute it with different input data. 2. Write pseudocode for a program that allows the user to input...
Write a Java program that prompts the user to enter his/her name (first and last). Names...
Write a Java program that prompts the user to enter his/her name (first and last). Names are often expressed alphabetically as last name comma space first name. Display the user's alphabetical name and its length. Then output the user's initials. Finally, display the ASCII values of the initials with a space between them. Sample Output (input shown in italics) Enter your full name Jane Doe Your alphabetical name Doe, Jane is 9 characters long Your initials are JD ASCII of...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT