Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ how do i get the winner of the elections name to be all caps #include #include #include using namespace std; int sumVotes(int list[], int

C++ how do i get the winner of the elections name to be all caps

#include

#include #include

using namespace std;

int sumVotes(int list[], int size); int winnerIndex(int list[], int size);

int main() { // declare array varaibles int totalVotes; int i;

cout << fixed << showpoint; cout << setprecision(2); cout << "Enter candidate's name and the votes received by " << "the candidate." << endl;

// load data into arrays string names[5]; int votes[5]; int size = 5; for (i = 0; i < size; ++i) { cout << "Name: "; cin >> names[i]; cout << "Votes: "; cin >> votes[i]; }

// set totalVotes totalVotes = sumVotes(votes, size); int winner = winnerIndex(votes, size);

cout << setw(9) << "Candidate" << setw(19) << "Votes Received" << setw(21) << "% of Total Votes" << endl; cout << setw(9) << "---------" << setw(19) << "--------------" << setw(21) << "----------------" << endl; for (i = 0; i < size; ++i) { cout << setw(9) << names[i] << setw(19) << votes[i] << setw(21) << (votes[i] * 100.0) / (totalVotes) << endl; }

cout << setw(49) << "-------------------------------------------------" << endl; cout << "Total " << setw(19) << totalVotes << endl; cout << "The Winner of the Election is " << names[winner] << "." << endl; // output winner return 0; }

int sumVotes(int list[], int size) { // Function Code int total = 0; for (int i = 0; i < size; ++i) { total += list[i]; } return total; }

int winnerIndex(int list[], int size) { // Function Code int ind = 0; for (int i = 0; i < size; ++i) { if (list[i] > list[ind]) { ind = i; } } return (ind); }

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

Students also viewed these Databases questions

Question

5-13. What might be some advantages of using mobile recruiting?

Answered: 1 week ago