Can't figure out this mode function
This is going on three days now. For back ground I will explain the rest of the code but won,t post it as the total is two hundred lines. I'm building a statistics program for an assignment. The code letts the user make three choices , 1 is enter data into an array, two is display the data i.e. Max, min, median, mode, variance and standard deviation. The third choice is to exit the program. This mode function works fine if I enter in a bunch of values where there is a mode, but if I enter one value and then display it it seems like it is not doing the test for mode. My original idea for the mode function if there is a mode is to create a countArray and increment the location with similar values further down the array. Does anyone see where I'm going wrong?
Code:
static int isThereMode(const float *data, int count){
int i,j;
int boolean;
int countArray[200];
float temp[200];
float tempHolder;
//create a temporary array that will be sorted
for(i=0;i<count;i++){
temp[i] = data[i];
}
//sort the temp array from lowest to highest
for(i=0;i<count;i++){
for(j=i+1;j<count;j++){
if(temp[i]>temp[j]){
tempHolder = temp[j];
temp[j] = temp[i];
temp[i]=tempHolder;
}
}
}
if(count==1){
boolean = 0;
}
//initialize the array to all zeros
for(i=0;i<count;i++)
countArray[i]=0;
for(i=0;i<count;i++){
for(j=i+1;j<count;j++){
if(data[i]!=data[j]){
printf(" debug there is no equal data in array\n");
boolean = 0;
}
else if(data[i]==data[j]){
boolean = 1;
}
}
}
return boolean;
}
static float modeOfValues(const float *data,int count){
int meanCounter = 0;
int position = 0;
int i,j;
float mode;
int countArray[200];
float temp[200];
float tempHolder;
for(i=0;i<count;i++){
temp[i] = data[i];
}
for(i=0;i<count;i++){
for(j=i+1;j<count;j++){
if(temp[i]>temp[j]){
tempHolder = temp[j];
temp[j] = temp[i];
temp[i]=tempHolder;
}
}
}
for(i=0;i<count;i++)//initialize the array to all zeros
countArray[i]=0;
/*look at the first element in the data array and compare it to the
the next element in the array, if there are matches increment the
countArray location where a match occurs */
for(i=0;i<count;i++){
for(j=i+1;j<=count;j++){
if(data[i] == data[j]){
countArray[i]+=1;
}
}
}
/*check the countArray for the highest number */
for (i=0;i<count;i++){
if(countArray[i] > meanCounter){
meanCounter = countArray[i];
position = i ;
}
}
mode = data[position];
return mode;
}