Voting system
#1

Hello. I've a question about a voting system I'm creating now. For an example a dialog appears for every player and they have to vote for the map which player likes. The system recieved results such as:

Map1- 8
Map2- 2
Map3- 9
Map4- 5


Now a question. How to get map which has the most votes?
Reply
#2

Let's say you have map[0] = 8, map[1] = 2....map[4] = 5.
I'm sure there are better ways but this should work
Код:
new index, largest;
// Loop through the whole array.
for(new i = 0; i < 4; i++)
{
	if(map[i] > largest)
	{
            // Update the index
	    index = i;
           // Update the largest value.
	    largest = map[i];
	}
}
now map[index] is the array with the largest value.
But of course you have to change "4" to the number of maps and store values in an array.
Reply
#3

Thanks for advice. I'll check it in the morning.
Reply
#4

Let me know when you test it. Good luck.
Reply
#5

Yes! It works. Thank you a lot!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)