// Steve J. Hodges // CS19: C++ Programming // find the mode in an array #include using namespace std; int findMaxPos(int [], const int); main(){ int votes[11]={0}; // init - no votes int vote; cout << "Welcome to the Governor rating program!" << endl; cout << "Enter the votes (values from 1 worst to 10 best)" << endl; cout << "Enter any other value to quit" << endl; cout << "Your vote (1 worst - 10 best)?"; cin >> vote; while (vote > 0 && vote < 11){ votes[vote]++; cout << "Your vote (1 worst - 10 best)?"; cin >> vote; } // while cout << endl << "Vote totals:" << endl; cout << "rating" << "\t" << "count" << endl; for (int i = 1; i< 11; i++){ cout << i << "\t" << votes[i] << endl; } cout << findMaxPos(votes, 11) << " got the most votes" << endl; } int findMaxPos(int ta[], const int S){ int max = ta[1]; int pos = 1; for (int i=2; i< S; i++){ if (ta[i] > max){ max = ta[i]; pos = i; } } return pos; }