write a method that calculates the mode of integers within an array?

I have a program where the user inputs numbers and the program calculates the mean median and mode. everything works fine except the mode method, and I dont know why. here is some of the code. I included a method I call that sorts the array, and that may or may not be the problem, but otherwise I just want this to work!!! :/

Code:

`void sortArray(int nums[], int total) {`

int x;

int y;

for(x=0; x<total; x++) {

for(y=0; y<total-1; y++) {

if(nums[y]>nums[y+1]) {

int temp = nums[y+1];

nums[y+1] = nums[y];

nums[y] = temp;

}

}

}

}

int findMode(int nums[],int total) {

int i, j, maxCount, modeValue;

int tally[total];

for (i = 0; i < total; i++) {

tally[nums[i]]++;

}

maxCount = 0;

modeValue = 0;

for (j = 0; j < total; j++) {

if (tally[j] > maxCount) {

maxCount = tally[j];

modeValue = j;

}

}

return modeValue;

}