after hours of trying (im really new to C++), i got a program to run that will find the mean, median, mode, and standard deviation of an array of numbers. However, if there is no mode (every number only appears once), it just returns the first number for mode. if there is more then one mode, it just returns the first mode. ive tried using a few if statements, but it screwed up everything and wouldnt run. ::points down:: this way will run. any suggestions on what i can do to make it happen?
//MODE HERE
int modeIndex=0;
int modeFrequency=0;
int maxModeIndex=0;
int maxModeFrequency=0;
for(int i=0 ; i<length ; i++)
{
if(list!=list[modeIndex])
{
if(modeFrequency>1)
{
cout<< list[modeIndex] << " occurs " << modeFrequency << " number of times" << endl;
}
if(modeFrequency>maxModeFrequency)
{
maxModeIndex = modeIndex;
maxModeFrequency = modeFrequency;
}
modeIndex = i;
modeFrequency=1;
}
else
{
modeFrequency++;
}
}
// validate the last set of elements in the list.
if(modeFrequency>1)
{
cout<< list[modeIndex] << " occurs " << modeFrequency << " number of times" << endl;
}
if(modeFrequency>maxModeFrequency)
{
maxModeIndex = modeIndex;
maxModeFrequency = modeFrequency;
}
cout<< "Mode is: " << list[maxModeIndex] << endl;
return 0;