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, the votes received by that 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.

1 answer
Question:

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, the votes received by that 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.

Answers

Answer:#include <iostream>#include <string>using namespace std;int main(){    string names[5];    int votes[5];    for(int i=0;i<5;i++)    {        cout<<"Enter candidate name"<<endl;       getline(cin,names[i]);        cout<<"Enter candidate votes"<<endl;        cin >> votes[i];  cin.ignore();    }int total_votes=0;int max =-1;int max_val=0; for(int i=0;i<5;i++)    {        total_votes=total_votes+votes[i];        if(max_val<votes[i])        {            max_val=votes[i];            max=i;        }            }    cout<<"Total votes"<<total_votes<<endl;    for(int i=0;i<5;i++)    {        float per=(votes[i]/total_votes)*100;        cout<<"float per"<<per<<endl;        cout<<" "<<names[i]<<" "<<votes[i]<<" "<<per<<" %" <<endl;    }        cout<<"Winner is  "<<names[max]<<" "<<votes[max]<<endl;    return 0;}Explanation:Define a string array of size 5 for names. Define one integer array of size 5 for votes. Take input from user in loop for string array and int for votes.In another loop find maximum of the list and sum all the votes. Store max votes index in max variable. In another loop display names along with their votes and percentage.Display winner name and votes using max as index for name and votes array.

Similar Solved Questions

2 answers

You (informal) run usted corra usted corre tú corres tú corras

you (informal) run usted corra usted corre tú corres tú corras...
1 answer

Will Someone Please Answer, Would the rules for interference work the same for light waves as they do for sound waves? Explain why or why not

Will Someone Please Answer, Would the rules for interference work the same for light waves as they do for sound waves? Explain why or why not...
1 answer

A violin string vibrates at 441 hz when unfingered. at what frequency will it vibrate if it is fingered one-third of the way down? (only two thirds of the string vibrates.)

A violin string vibrates at 441 hz when unfingered. at what frequency will it vibrate if it is fingered one-third of the way down? (only two thirds of the string vibrates.)...
1 answer

The tendency for individuals to attribute their own successes to internal factors and put the blame for failures on external factors is known as confirmation bias. a. True b. False

The tendency for individuals to attribute their own successes to internal factors and put the blame for failures on external factors is known as confirmation bias. a. True b. False...
1 answer

The complication to the Schrodinger equation in multi-electron systems arises because: protons in the nuclei attract each other. electrons repel each other. electrons attract each other. electrons are repelled by the nucleus.

The complication to the Schrodinger equation in multi-electron systems arises because: protons in the nuclei attract each other. electrons repel each other. electrons attract each other. electrons are repelled by the nucleus....
1 answer

According to loftus why is the study of eyewitness memory important be

According to loftus why is the study of eyewitness memory important be...
2 answers

There are 11 students in your class. In how many ways a group of 4 students will be selected to participate in a social campaign such that you will always be included in the group to lead the event?

There are 11 students in your class. In how many ways a group of 4 students will be selected to participate in a social campaign such that you will always be included in the group to lead the event?...
2 answers

What is the meaning of the phrase "living in a glass house" A. living a very public life B. living a very private life C. cleaning lots of windows D. having many accidents

What is the meaning of the phrase "living in a glass house" A. living a very public life B. living a very private life C. cleaning lots of windows D. having many accidents...
1 answer

65 <658 im bi i want a boy friend im james i play guetar and scatebord lets talk some stu.pid panguin dude deleted my other account love yall

65 <658 im bi i want a boy friend im james i play guetar and scatebord lets talk some stu.pid panguin dude deleted my other account love yall...
1 answer

ANYONE KNOW HOW TO STOP HICCUPING

ANYONE KNOW HOW TO STOP HICCUPING...
2 answers

GIVING BRAINLIEST Pls Help. Explain If You Can

GIVING BRAINLIEST Pls Help. Explain If You Can...
1 answer

What is defined as "the withdrawal of investments from activities (and regions) that yield low rates of profit in order to reinvest in new activities (and new places)"?

What is defined as "the withdrawal of investments from activities (and regions) that yield low rates of profit in order to reinvest in new activities (and new places)"?...
1 answer

What is the potential danger from an accident at a nuclear power plant? A) fire and large scale explosions B) exposure to radiation C) meltdown of the plant and surrounding community D) entire cities could be wiped out

what is the potential danger from an accident at a nuclear power plant? A) fire and large scale explosions B) exposure to radiation C) meltdown of the plant and surrounding community D) entire cities could be wiped out...
2 answers

Question: Protons, neutrons, and electrons are arranged differently in atoms of different elements. True false

Question: Protons, neutrons, and electrons are arranged differently in atoms of different elements. True false...
2 answers

Best answer gets brainlist

Best answer gets brainlist...
2 answers

Which statements is true regarding selective breeding ? 1. selective breeding only works in plants 2. selective breeding produces changes in genes 3. selective breeding only words in animals 4. all of the above

which statements is true regarding selective breeding ? 1. selective breeding only works in plants 2. selective breeding produces changes in genes 3. selective breeding only words in animals 4. all of the above...
2 answers

What is the value of y? 3y+104=2

What is the value of y? 3y+104=2...
1 answer

The scientific name for a white oak is Quercia Alba; the scientific name for a red oak is Quercia Ribera what does this tell you about the organism?

The scientific name for a white oak is Quercia Alba; the scientific name for a red oak is Quercia Ribera what does this tell you about the organism?...
1 answer

Please help I don't understand how to answer this please help I will brainlist if you get it correct

please help I don't understand how to answer this please help I will brainlist if you get it correct...

-- 0.012336--