1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
#include <iostream>
#include <string>
using namespace std;
int main()
{
int option;
string player[10] = {
"Lionel Messi", "Arjen Robben", "Thomas Muller", "James Rodriguez",
"Neymar da Silva Santos Junior", "Christiano Ronaldo", "Jan Vertonghen",
"Robin van Persie", "Miralem Pjanic", "Karim Mostafa Benzema"
};
int votes[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
// show options
for (int i = 0; i < 10; i++)
cout << "\t" << i + 1 << "\t" << player[i] << endl;
do
{
// read vote, make sure we are in the menu range
do {
cout << endl << "\tEnter Choice (or type 11 to finish): ";
cin >> option;
// bit of code to stop the annoying loop if user enters
// a letter and not the expected number range.
cin.clear(); // clear any error flags
cin.ignore(1, '\n'); // discard any newline left in the stream.
} while (option < 0 || option > 11);
// make sure we are not exiting.
if (option < 11) {
// store vote in array and loop for another.
// the option value would be used to access
// and modify the correct player.
option--; // arrays start at 0, not 1
}
} while (option != 11);
// bubble sort in decending order, remember you also need to
// include the players in the sort so that element index's
// remain lined up.
// loop and show the first 5 names (the first 5 highest)
return 0;
}
|