# Thread: Find me this last syntax error!

1. ## Find me this last syntax error!

I receive the error right on the last line that contains the final bracket of the program and i have no idea why maybe a new set of eyes can help me
Code:
```#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#define ARRAY_SIZE 50

void fill(int a[]);
void sortArray(int a[]);
double findMean(int a[]);
double get_median(int a[]);
int findMode(int a[]);
void printResults(double mean, double median, double mode);

int
main(void)
{

//variables
double mean, median, mode;
int array[ARRAY_SIZE];

// fill, sort and print array
fill(array);
sortArray(array);

//define and calculate mean median mode
mean = findMean(array);
median = get_median(array);
mode = findMode(array);

//Print Results
printResults(mean, median, mode);

return 0;
}

// functions

//fills array a with random numbers from 0-100.
void fill(int a[]) {
int i;
struct timeval tv;

gettimeofday(&tv, NULL);
srand(tv.tv_usec);

for(i = 0; i < ARRAY_SIZE; i++) {
a[i] = rand() % 101;
}
}

//sorts array out
void sortArray(int a[])
{
int i,
temp,
j;

for (i=0; i < i-1; ++i)
{
if ( a[i] > a[j] )
{
temp = a[i] ;
a[i] = a[j] ;
a[j] = temp ;
}
}
printf("%d ", a[i]);
}

//Mean function >:I

double findMean(int a[])
{
int i;
double sum = 0.0;
for(i = 0; i < ARRAY_SIZE; i++) {
sum += a[i];
}
return (sum/ARRAY_SIZE);
}

//Median Fucntion

double get_median(int a[]) {
double median;
int x,y;

if(ARRAY_SIZE % 2 == 1) { //array_size is odd
x = a[ARRAY_SIZE / 2];
y = a[ARRAY_SIZE / 2 - 1];
median = ((double)x + y)/2.0;
} else { //array_size is even
median = a[ARRAY_SIZE / 2];
}

return median;
}

//Mode Function

int findMode(int a[])
{
int i, j, maxCount, modeValue;
int tally[ARRAY_SIZE];
for (i = 0; i < ARRAY_SIZE; i++) {
tally[a[i]]++;
}
maxCount = 0;
modeValue = 0;
for (j = 0; j < ARRAY_SIZE; j++) {
if (tally[j] > maxCount) {
maxCount = tally[j];
modeValue = j;
}
}
return modeValue;
}

//Print out results

void printResults(double mean, double median, double mode)
{
printf("Mean: %d\tMedian: %d\tMode: %i", mean, median, mode);
}
}```

2. how many }'s are at the end of the file?

3. A consistent indentation style would go a long way here. Half the time you put it at the end of the line and half the time its on the next line.
However, doesn't line 126 appear to be quite an obvious mistake?

You might also like to know that your sortArray function is horendously broken.
Turn on your compiler warnings and pay attention to them.

4. Code:
```#define ARRAY_SIZE 50
...
void fill(int a[]) {
...
for(i = 0; i < ARRAY_SIZE; i++) {
a[i] = rand() % 101;
...
}
...
int findMode(int a[])
{
int tally[ARRAY_SIZE];
for (i = 0; i < ARRAY_SIZE; i++) {
tally[a[i]]++;```
What are the initial values for "tally"?
What are the possible values for "a[i]" and what are the valid indices for "tally"?

Your median calculation is wrong too. It should be the other way around.

Bye, Andreas