Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

------PROGRAM IN C------- In a primary election the results from the mayor's race have been reported by each precinct as follows: Votes Cast in Primary

image text in transcribed

------PROGRAM IN C-------

In a primary election the results from the mayor's race have been reported by each precinct as follows: Votes Cast in Primary Election Candidate PrecinctPrecinct 2 Precinct 3 Precinct 4 Precinct 5 192 48 206 147 90 312 267 13 382 186 114 21 408 39 38 Declare the following 1) 5int arrays(with 4 elements each, each array representing a precinct... each element is the number of votes for particular candidate) with the votes cast as shown in the table above. Set up a.txt datafile to read in values. There are many ways to set up the datafile. One might look like this: 192 147 186 114 267 48 90 12 21 13 Read the data into your array (s) from the datafile Call a function totals. This function will have as parameters the array(s) of votes cast, a one-dimensional array of candidate vote sums, a one-dimensional array of percentagesttype double). In the function determine the following: the sum of all votes cast the number of votes cast for each candidate the percentage of the total votes cast that each candidate received As you are calculating, place the vote totals and the percentages into one-dimensional arrays. You do not need to return the total votes cast, but must calculate it to determine percentages. Call a second function printResults. Parameters for this function should be the one-dimensional array of candidate totals, and the one-dimensional array of percentages. In the function print the total votes cast for each candidate and the percentage of each candidate in a table. Example: 906 votes 33.7% Cand. 1 Cand 2 Also in the printResults function, check with an if statement in a loop to see if any of the candidates received more than 50% of the votes cast. If so, declare that candidate to be the winner. If not, print a statement that a runoff is required

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transact SQL Cookbook Help For Database Programmers

Authors: Ales Spetic, Jonathan Gennick

1st Edition

1565927567, 978-1565927568

More Books

Students also viewed these Databases questions

Question

What is Indian Polity and Governance ?

Answered: 1 week ago