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
irina [24]
3 years ago
15

write a c++program that allows the user to enter the last names of fivecandidates in a local election and the number of votes re

ceived byeach candidate. The program should then output each candidate'sname, the number of votes recieved, and the percentage of the totalvotes received by the candidate. Your program should also outputthe winner of the election.
Computers and Technology
1 answer:
madreJ [45]3 years ago
5 0

Answer:

#include<iostream>

#include<stdlib.h>

using namespace std;

int main(){

   //initialization

   string str1[5];

   int arr_Vote[5];

   int Total_Vote=0,max1_Index;

   int max1=INT_MIN;

   //loop for storing input enter by user

   for(int i=0;i<5;i++){

       cout<<"Enter the last name of candidate: "<<endl;

       cin>>str1[i];

       cout<<"Enter the number of vote receive by the candidate: "<<endl;

       cin>>arr_Vote[i];

       //calculate the sum

       Total_Vote = Total_Vote + arr_Vote[i];

       //find the index of maximum vote

       if(arr_Vote[i]>max1){

           max1=arr_Vote[i];

           max1_Index=i;

       }

   }

   //display

   cout<<"\nThe output is......"<<endl;

   //loop for display data of each candidate

   for(int i=0;i<5;i++){

       cout<<str1[i]<<"\t"<<arr_Vote[i]<<"\t"     <<float(arr_Vote[i]*100)/Total_Vote<<"%"<<endl;

   }

   //display winner

   cout<<"The winner candidate is"<<endl;

   cout<<str1[max1_Index]<<"\t"<<arr_Vote[max1_Index]<<"\t"<<float(arr_Vote[max1_Index]*100)/Total_Vote<<" %"<<endl;

}

Explanation:

Create the main function and declare the two arrays and variables.

the first array for storing the names, so it must be a string type. second array stores the votes, so it must be int type.

after that, take a for loop and it runs for 5 times and storing the values entered by the user in the arrays.

we also calculate the sum by adding the array data one by one.

In the same loop, we also find the index of the maximum vote. take an if statement and it checks the element in the array is greater than the max1 variable. Max1 variable contains the very small value INT_MIN.

If condition true, update the max1 value and update the max1_Index value.

The above process continues for each candidate for 5 times.

After that, take a for loop and display the data along with percentage by using the formula:

Vote\,percent=\frac{Vote\,receive*100}{Total\,vote}

the, finally display the winner by using the max1_Index value.  

You might be interested in
What does pagination mean in Microsoft Word?
marin [14]

it means to alt f4 then that would help so it can eat the microscope then have it digested

5 0
3 years ago
Read 2 more answers
What is ms- power point?​
WITCHER [35]

Answer:

Microsoft PowerPoint is a powerful slide show presentation program. It is a standard component of the company's Microsoft Office suite software, and is bundled together with Word, Excel, and other office productivity tools. The program uses slides to convey information rich in multimedia.

hope it work️

5 0
3 years ago
Read 2 more answers
How do you understand a scientific problem? Give two (2) examples of a scientific problem you
Brums [2.3K]

Answer:

i need free points im sry

Explanation:

8 0
3 years ago
What are the different components of the cloud architecture?
sashaice [31]

Cloud computing architecture can be described as components and subcomponents required for cloud computing. Typically, these components consist of front (fat client, mobile device, thin client) and black end platforms (storage, servers), a cloud based delivery, and a network (Internet, Internet, Cloud). When all of these components are combined, they make up a cloud architecture.

3 0
3 years ago
8.22 what is the maximum amount of physical memory
sammy [17]
2.16 would be your correct answer or you could refer to the source to actually explain trust me it will help ! the source > coursehero.com
5 0
3 years ago
Other questions:
  • Which two things will you see when you collapse the view of the subdocument in a master document? (Microsoft Word)
    8·2 answers
  • When creating an electronic slide presentation, Eliza should ensure that her presentation contains
    6·1 answer
  • The Freemont Automobile Factory has discovered that the longer a worker has been on the job, the more parts the worker can produ
    11·1 answer
  • What is the wave speed of a wave that has a frequency of 100 Hz and a wavelength of 0.30m?
    5·1 answer
  • 3. Which one of the following statements is true for spell checkers?
    11·1 answer
  • Complete the PizzaCaloriesPerSlice() function to compute the calories for a single slice of pizza. A PizzaCalories() function re
    6·1 answer
  • E. what component must be compatible with every other component of the computer?
    15·1 answer
  • Using this tool to help you to visualize your slides and develop your content
    13·1 answer
  • A major retailer wants to enhance their customer experience and reduce losses
    9·1 answer
  • What are the advantages of hybrid computer
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!