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
il63 [147K]
3 years ago
14

Write a program that allows the user to enter the last names of five candidates in a local election and the number of votes rece

ived by each candidate. The program should then output each candidate's name, the number of votes received, and the percentage of the total votes received by the candidate. Your program should also output the winner of the election.
i have this
#include
#include
#include
using namespace std;
int findMax(int votes[]);
void main()
{
int votes[20];
string name[10];
int total=0;
float percent[10];
int m, i, loc;
cout<<"Enter the names of candidates in local election and number of votes:"< for(int i=0;i<5;i++)
{
cin>>name[i];
cin>>votes[i];
}
for(i=0;i<5;i++)
{
total=total+votes[i];
}
for(i=0;i<5;i++)
{
percent[i]=((votes[i]/total)*100);
}
cout<<"Candidate"<<'\t'<<"VotesReceived"<<'\t'<<"% of Total Votes"< cout< for(i=0;i<5;i++)
{
cout< }
cout<<"Total:"< m=findMax(votes);
cout<<"Winner of the election is"< system("pause");
}
int findMax(int votes[])
{
int i,max,loc;
max=votes[0];
for(i=1;i<5;i++)
{
if(votes[i]>max)
{
max=votes[i];
loc=i;
}
}
return loc;
}
But, it is saying that loc is not initialized, and it is also not calculating % of total votes or the winner of the election and I don't what to do to fix it.
Computers and Technology
1 answer:
nydimaria [60]3 years ago
3 0

Answer:

The following fix were made to the program

  1. Change void main() to int main(), then set a return value at the end of the main function;  e.g. return 0
  2. Remove system("pause");  It's not needed
  3. For each of the array, change their lengths to 5 i.e. int votes[5];  string name[5];   and float percent[5];
  4. Lastly, calculate the percentage using: percent[i]=((votes[i]*100.0/total))

Explanation:

(1) void main implies that the main function will not return any value. So, you change it to int main() and then set the return value

(2) There is no need to pause the program, so system.("pause") is not necessary.

(3) The question says there are 5 candidates. So, we set the arrays to accommodate inputs for 5 values

(4) percent array is declared as float; 100.0 will ensure that it calculates the percentage as a float value.

<em>See attachment for updated code</em>

Download cpp
You might be interested in
The best way to ensure the accuracy and safety of your accounts is to:
Gekata [30.6K]
Use symbols and a different password for each one

6 0
3 years ago
What are the possible consequences if you fail to identify system requirements correctly and completely?
AlladinOne [14]
There are a few consequences for failing to identify system requirements. 

1. Strain on time and effort which can cost money for either a company or yourself (depending if you are an employer, employee, etc).

2. Additional costs for hardware. If you decide to upgrade your hardware on a later time. It will cost additional money for repairs and replacements to adjust.

3. It can cause dissatisfaction to a user if you are working as a technician (for example) which can leave a negative mark on your reputation/resume) 
4 0
4 years ago
Given six memory partitions of 300 KB, 600 KB, 350 KB, 200 KB, 750 KB, and 125 KB (in order). The memory allocation algorithm th
Makovka662 [10]

Answer:

The memory allocation algorithm that is used to place the processes given is the <u>First Fit Algorithm </u>

Explanation:

The First Fit Management Algorithm works by ensuring that the pointer keeps track of all the free spaces in the memory and accepts and executes all instructions to allocate a memory block to the coming process as long as it is big enough to hold the size of the process.

For example, the First Fit algorithm will allocate the processes in the first block that fits (that is, if it can fit the memory bock in the queue, then the process will be store)

It will work as follows (recall that the memory partitions are in order and must remain so):

A) 115 KB is stored in 300KB block, leaving the following free spaces (185KB, 600KB, 350KB, 200KB, 750KB, 125KB), next

B) 500 KB is store in a 600KB block leaving the following free spaces (185 KB, 100  KB, 350 KB, 200 KB, 750 KB, 125 KB), next  

C) 358 KB is stored in 750KB block, leaving the following free spaces (185KB, 100KB, 350KB, 200KB, 392KB, 125KB)  next

D) 200 KB is stored in 350KB block, leaving the following free spaces (185 KB, 100 KB, 150KB, 200KB, 392KB, 125KB)  next

E) 375KB is stored in 392KB block leaving (185KB, 100KB, 150KB,  200KB, 17KB, 125KB)

One of the demerits of this Algorithm is that, as shown above, memory is not maximized. It however is one of the easiest algorithms amongst all the other memory allocation processes.

Cheers

5 0
3 years ago
How to relaunch Yahoo mail? I keep getting error code 17 when I try to open my Yahoo mail. With the relaunch of the Yahoo! Mail
solmaris [256]
IM NOT SURE!!!!!!!........................................
3 0
4 years ago
The front surface of the CCD is called the _________
Bogdan [553]
Fiber optics. Hope this helps


5 0
4 years ago
Other questions:
  • Write a multithreaded program that generates the Fibonacci series using Pthreads thread library. This program should work as fol
    10·1 answer
  • Python Write a program that asks the user for an integer and then prints out all its factors.
    12·1 answer
  • Which type of firewall automatically adjusts its filtering rules based on the content of the traffic of existing sessions?
    8·1 answer
  • A network using multiple cell towers falls under which type of network?
    13·1 answer
  • True or False: The correct answer to a numeric entry field will appear only if you click on the fields themselves after selectin
    12·1 answer
  • Given 4 floating-point numbers. Use a string formatting expression with conversion specifiers to output their product and their
    6·1 answer
  • Which of these converts the reciprocating motion of the piston into rotary motion?
    7·1 answer
  • We can save our data peremently on a
    7·2 answers
  • Five real world objects with similar characteristics​
    6·1 answer
  • you are a new lenovo service provider and need to use the recovery utility information on the lenovo support website. this infor
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!