Hey, so I need to calculate and display the mode (most frequently occuring number) from a vector of ints. I already have the vector, and it can have any number of elements in it. So now i need to figure out a way to loop through my vector to figure out the number that occurs most. I also need a message that says "No Mode" if there is an equal number of every number.
This is what I have so far but it doesn't work very well. Could any1 help me out? Vector is called "v"
double previous = 0;
double current = 0;
double mode = 0;
for (int i = 0; i < v.size(); i++)
{
for (int j = 0; j < v.size(); j++)
{
if (v[j] == v[i])
current++;
}
if (current > previous) {
mode = v[i];
previous = current;
current = 0;
}
}
cout << "Mode = " << mode << endl;