1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Triss [41]
3 years ago
12

Write a program that allows the user to enter the last names of five candidates in a local election and the votes received by ea

ch 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.
Computers and Technology
1 answer:
blsea [12.9K]3 years ago
7 0

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.

You might be interested in
What is qwerty and why is it on the keyboard?
Genrish500 [490]

Answer:

qwerty is the main way people sort out there keyboard as you can see on the left side of the keyboard there is W,A,S,D

Explanation:

6 0
4 years ago
Read 2 more answers
Which of the following best describes a computer virus? another name for a software bug the product of a computer crash software
nikdorinn [45]
A computer virus is software that can spread itself
8 0
4 years ago
Read 2 more answers
When the atmosphere has too much carbon dioxide in it, the oceans absorb some of it to achieve a new balance. This is an example
horsena [70]
The answer is B. 
A geochemical cycle. 
8 0
4 years ago
Read 2 more answers
(TCO G) _____ is when network managers deal with network breakdowns and immediate problems instead of performing tasks according
NeTakaya

Option D

Firefighting is when network managers deal with network breakdowns and immediate problems instead of performing tasks according to a well laid out plan.

<h3><u>Explanation:</u></h3>

Network management is a process of monitoring, operating and controlling the network. Various network managers spend most of their time firefighting- dealing with breakdowns and urgent problems.

If managers do not allocate enough time planning and organizing the network and networking staff, they are intended to be reactive rather than proactive in solving problems. A term that refers to reacting to network problems as they arise rather than relying on planned network management activity

4 0
3 years ago
It is the "executable" phrase of Word<br>Wide Web with dynamic applications,?<br>​
Mkey [24]

Answer:

It is the “executable” phrase of Word Wide Web with dynamic applications, interactive services, and “machine-to-machine” interaction. In Web 3.0, computers can interpret information like humans and intelligently generate and distribute useful content tailored to the needs of users.

4 0
3 years ago
Other questions:
  • A search engine is the same as a browser.<br> \
    11·1 answer
  • a solid state drive is a removable flash memory device that you insert and remove from a slot in a computer, mobile device, or c
    5·1 answer
  • A palindrome is a word or phrase that reads the same both backward and forward. The word ""racecar"" is an example. Create an al
    15·1 answer
  • What is the printout for the first statement in the main method?
    13·1 answer
  • Describe the steps to play a presentation the way your audience will see it.
    8·2 answers
  • Mr. Ray is looking for a platform to launch his product. His marketing team advises him to launch the product via as it is free
    15·2 answers
  • Which function in Excel tells how many
    6·1 answer
  • You started writing a paper yesterday. You worked on it again today. After a few hours, you realized that you have introduced so
    15·2 answers
  • What is the common term used to describe a single computer document?
    15·2 answers
  • Technology that transfers page images composed inside a computer directly to printing plates is called:
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!