I've been at this for a few hours now. I've been trying to find the mode in the const data array. Here is my code so far
Code:
static float modeOfValues(const float *data,int count){
int meanCounter = 0;
int i,j;
float mode;
int counter = 1;
int countArray[200];
for(i = 0;i < count;i++)//initialize the count array to all zeros
countArray[i]=0;
for(i=0;i<count;i++){
for(j=i+1;j<count;j++){
if(data[i]==data[j]){
countArray[i]=counter+1;
printf("counter%d\n",counter);
}
}
}
for(i=0;i<count;i++)
printf("%d\n",countArray[i]);
for (i=0;i<count;i++){
if(countArray[i] > meanCounter){
meanCounter = data[i];
}
else if(countArray[i] < meanCounter){
meanCounter = data[i];
}
}
mode = data[meanCounter];
return mode;
}
I'm trying to create an array that will hold how many times a number comes up in the original array, but the numbers in the counter array are not getting incremented the way I hope they do. Can anyone see something I can't ?