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
If involved in a boating accident causing serious bodily injury or death while boating under the influence, the operator has com
9966 [12]

Answer:

felony

Explanation:

It is an offence on the part of a boat operator who is under the control of alcohol while boating, as such could result in property damage, serious bodily injury or death. Where such leads to bodily injury or deaths, the operator could be convicted for felony while misdemeanor applies to property damage.

There have been a reoccurring boating incidence in the country especially in the state of Florida, which has the highest number of boating fatalities hence created stiff penalties for boating under the influence of alcohol.

While it is adviseable for motorists not to drink and drive, it is also not lawful be under the influence when boating as such could cause injury, deaths or property damage and such operator would receive appropriate penalty depending on the outcome of the incident.

6 0
3 years ago
Create a class called Book with the following properties using appropriate data types: Title, Author, numberOfPages, Create a se
tamaranim1 [39]

Answer:

I don't know the answer sorry

7 0
3 years ago
Whereas lines of competition are clearly defined in the more established industries, in the Internet industry they are blurred a
Zarrin [17]

Answer:

Whereas lines of competition are clearly defined in the more established industries, in the Internet industry they are blurred and indistinct, as companies that compete one day may be partners the next. So "Lines" cannot be compared to/with internet companies.

Explanation:

The Internet Industry  is shaped by its unique framework outlining and its own rules between the companies within it, which offer a vast number of products and services and not always competing with each other compared with the traditional established industries competition lines that were developed from two parties or more aiming the same unshareable goal. These industries are stablishing the lines of competitions predicament which by all means can not be measured and applied using the same criteria for both of them.

The online industry is claiming for flexible, pliant lines of competition to be inforced to its specific logic and mechanisms.

The companies are now in a brand new competing ground with the digital area, so traditional established bart lines of competition although clear and defined are becoming obsolete facing the current surprising thus blurred and indistict internet industry lines.

6 0
2 years ago
Choose the correct statement:_______.
olga2289 [7]

Answer:

d. A String is a class data type so a String variable holds a reference to a location in memory

It depends on which programing language or scripting language...

Explanation:

If it's Java then D is the correct answer...

6 0
2 years ago
What specific type of DNS query instructs a DNS server to process the query until the server replies with an address that satisf
Kaylis [27]
Unsure how it is to be answered
8 0
3 years ago
Other questions:
  • Unix/linux are ____ systems, which let many people simultaneously access and share the resources of a server computer.
    13·1 answer
  • Because you do not know every possible future use for the data TerramEarth collects, you have decided to build a system that cap
    15·1 answer
  • A __engineer specializes in computer hardware design and integration.
    15·1 answer
  • A. True
    8·2 answers
  • Which of the following SQL statements will display all customers who have not recently placed an order? a. SELECT customer# FROM
    15·1 answer
  • In Microsoft Word, spelling errors are identified by a _____.
    5·2 answers
  • Name two ways you can identify the pid number of the login shell.
    13·1 answer
  • Smart art is considered a​
    14·1 answer
  • A computer is the __________ of an attack when it is used to conduct an attack against another computer.
    11·1 answer
  • A company is looking for an employee to help organize customer information for the sales team. Which computer field includes thi
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!