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
A ____________ is a collection of infected IT devices that an attacker or attack group controls.
sattari [20]
The answer would be a Botnet .
8 0
3 years ago
A user is trying to log into windows on her notebook computer. she enters the correct password for her user account, but the sys
ASHA 777 [7]
Try restarting the PC. I have the same issue on Windows 10 sometimes generally its a network error because Windows 10 has a lot of internet required features... 
7 0
4 years ago
Who are the founders of the video-sharing site Blip?
rewona [7]

the Founders would be Justin Day


3 0
4 years ago
How many integer types are there in python​
Setler79 [48]
In python you can have several types of numbers such as plain integers, long integers, floating-point numbers and complex numbers.
5 0
3 years ago
A database at a college is required to support the following requirements. Complete the information-level design for this set of
Maslowich

Answer:

Explanation:

check the attached files below for answers to your question, thanks.

6 0
3 years ago
Other questions:
  • What are parts of the prewriting process
    13·1 answer
  • Gwen's company is planning to accept credit cards over the Internet. Which one of the following governs this type of activity an
    13·1 answer
  • In preparing his persuasive presentation, Reza should most likely focus on clearly presenting his
    6·2 answers
  • Which best describes the Help feature of Word?
    13·2 answers
  • A magnetic disk drive requires a motor to position a read/write head over tracks of data on a spinning disk, (see fig. e4.4 in d
    8·1 answer
  • Given the following code, what are the dimensions, in pixels, of the shape created? import tkinter class myShape: def __init__(s
    6·1 answer
  • Which two components help input data in a computer and select options from the screen, respectively?
    9·1 answer
  • Which of these is an example of input?
    6·1 answer
  • Select the statement which most accurately describes the benefits and drawbacks of working from home and telecommuting.
    13·2 answers
  • Which type of information should never be given out on social media?
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!