I'm trying to find the mode of a vector full of ints. To do so I created a map an tried to make it so that evey time a number occurs it increments the related key on the map. Right now I'm just getting the highest number in the vector instead of the number that occurs the most.

map<int,unsigned> frequencyCount;
	//This is my attempt to increment the values of the map everytime one of the same numebers 
	for(size_t i = 0; i < v.size(); ++i)
		frequencyCount[v[i]]++;

	unsigned currentMax = 0;
	unsigned checked = 0;
	for(auto it = frequencyCount.cbegin();
		it != frequencyCount.cend(); ++it )
		checked = it->first;
		if (checked > currentMax)
		{
			currentMax = checked;
		}
		
	cout << " The highest value within the map is: " << currentMax << endl;

why is there no enclosing brackets for the lines under for loop? Is it intentionally missed out? From the logic under for-loop, I don't think so

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.