Question: C++ Redo program using dynamic arrays. You must ask the user for the number of candidates and then create the appropriate arrays to hold the

C++

Redo program using dynamic arrays. You must ask the user for the number of candidates and then create the appropriate arrays to hold the data.

//header// #include #include #include

using namespace std; //function declaration// int voteamount(int list[], int size); int wintally(int list[], int size); //main start// int main() { //variables// string candidates[5]; int votes[5] = {0}; int totalVotes; int i; cout //decimal precision// cout cout "the>

for (i = 0; i //user input candidates// cin >> candidates[i] >> votes[i]; //calculate sum of votes// totalVotes = voteamount(votes, 5); //print votes received// cout for (i = 0; i cout (votes[i]) / static_cast(totalVotes)) * 100 cout cout system("PAUSE"); return 0; } //method for vote amount// int voteamount(int list[], int size) { int sum = 0; for (int i = 0; i //calculates the sum of votes// sum = sum + list[i]; //returns the value// return sum; } //method for winner tally// int wintally(int list[], int size) { int winInd = 0;

for (int i = 0; i //checks list with the index value// if (list[i] > list[winInd]) winInd = i; return winInd; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!