Q:

Finding multiple modes of a vector using maps c++

I am trying to write a function that takes a vector and then counts the frequency of each element in the vector using a map. The ones with the highest frequency get pushed into a new vector, and then I am trying to return the vector to be output in my main function.
vector<double> mode(vector<double> v)
{
    sort(v.begin(),v.end());
    vector<double> modes;
    map<int,double> frequencyCount;
    for(size_t i; i<v.size(); i++)
        frequencyCount[v[i]]++;
    double current_max = 0;
    for (auto iter = frequencyCount.cbegin(); iter != frequencyCount.cend(); ++iter)
    {
        if (iter ->second > current_max)
        {
        modes.push_back(iter->first);
        current_max = iter->second;
        }
    }
    if (current_max == 1)
    {
        cout << "No mode exists." << endl;
    }
    else
        return modes;
}

I then call it in main:
int main()
{
    vector<double> m = mode(v);
    cout << "Mode:    ";
    for (size_t i; i<m.size(); i++)
        cout << m[i];
}

no errors, but nothing is output... any advice?

A:

for(size_t i; i<v.size(); i++)

You forgot to initialize i to 0. The index variable is uninitialized. Undefined behavior.
Additionally, the overall algorithm could be improved in several ways, but that's not what was asked, here.

