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
Automate theory can be considered as science or art???
amm1812
I would say it is considered as science and a bit of maths as its the 'study of abstract machines and automata'
7 0
3 years ago
Read 2 more answers
Of the following, the greatest advantage of a database architecture is that
Zina [86]

Answer:

c.

Explanation:

Of the following, the greatest advantage of a database architecture is that data redundancy can be reduced. This refers to data being unintentionally repeated within the database causing space to be taken up unnecessarily. Database architecture allows for this problem to be addressed and prevented.

3 0
3 years ago
You just finished training a decision tree for spam classification, and it is gettingabnormally bad performance on both your tra
strojnjashka [21]

Answer:

Option B is the correct option.

Explanation:

The following answer is true because when the person completed our training of a decision tree and after the following presentation he getting not good working performance on both side i.e., test sets and during the training period. After the training there is no bug on the implementation of the presentation then, he has to increase the rate of the learning.

5 0
3 years ago
A ribbon is broken into 3 parts - name them. (From Microsoft Word 2016)
BARSIC [14]

Answer:

The Ribbon is composed of three parts: Tabs, Groups, and Commands.

4 0
3 years ago
WILL GIVE BRAINIEST! Your users are young children learning their arithmetic facts. The program will give them a choice of pract
Ierofanga [76]

In python:

numA = [4, 1, 6, 10, 2, 3, 7, 9, 11, 12, 5, 8]

numB = [2, 12, 10, 11, 1, 3, 7, 9, 4, 8, 5, 6]

while True:

   i = 0

   userChoice = input("Adding or Multiplying? (a/m) ")

   if userChoice == "a":

       while i < len(numA):

           answer = int(input("What is {} + {} ".format(numA[i],numB[i])))

           if answer == numA[i] + numB[i]:

               print("Correct!")

           else:

               print("That's incorrect. The right answer is {}".format(numA[i] + numB[i]))

           i += 1

   elif userChoice == "m":

       while i < len(numA):

           answer = int(input("What is {} * {} ".format(numA[i], numB[i])))

           if answer == numA[i] * numB[i]:

               print("Correct!")

           else:

               print("that's incorrect. The right answer is {}".format(numA[i] * numB[i]))

           i += 1

4 0
3 years ago
Other questions:
  • vulnerability is a feebleness which allows an attacker to condense a system's information assurance to security,is it true or fa
    14·1 answer
  • After completion of this chapter, you should be able to:  Describe the structure of an IPv4 address.  Describe the purpose of
    5·1 answer
  • Write a program that first gets a list of integers from input. The input begins with an integer indicating the number of integer
    7·1 answer
  • For a typical middle-income family, what is the estimated cost of raising a child to the age of 18?
    11·1 answer
  • Most C++ catastrophe vulnerabilities rely on uninitialized function pointers in a class.
    13·1 answer
  • Differentiate between perfect and imperfect market​
    14·1 answer
  • Alexis received paychecks from both her jobs and she would like to deposit them. One check is for $62.88 and the other is $523.2
    9·1 answer
  • What is a method that deletes an item from a list using the item’s value?
    11·1 answer
  • Programming Cycle. Arrange them in correct order​
    5·2 answers
  • What is computer fundamental ?
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!