Compile error on project. Expected initializer before 'sizeOfArray'

I've been working on a project. I have to find the mean and median of an array. I cannot get my code to compile. I keep getting the error "expected initializer before 'sizeOfArray'". Its on line 38 below. I don't think I'm missing a semicolon....

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <iostream>
using namespace std;
//prototyypes
float Mean (int* array, size_t size);
float Median (int* array, size_t size);
void Swap (int& x, int& y);
void Sort (int* array, size_t);

//main function
main()
{
	const size_t MAX_SIZE = 100;
	int array[MAX_SIZE];
	cout << "Enter integers('x' to stop)\n";
	size_t size = 0;
	while ((size < 100) && (cin >> array[size]))
	{
		size++;
	}
	cout << "Median: " << Median(array, size);
	cout << "Mean: " << Mean(array, size);
return 0;
}

//function implementations
float Mean(int numbers[],size_t sizeOfArray)
{
	float avg = 0;
	float sum = 0;
	for(int i = 0; i < sizeOfArray; i++)
	{
		sum +=(numbers[i]);
	}
	avg = sum/sizeOfArray;
	return avg;
}

float Median(int numbers[]),size_t sizeOfArray)
{
	sort(numbers, sizeOfArray);
	float med = 0;
	if (sizeOfArray % 2 == 0)
	{
		med = (numbers[sizeOfArray/2] + numbers[sizeOfArray/2-1]) / 2;
	}
	else 
	{
		med = numbers[sizeOfArray/2];
	}
	return med;
	
}

void Swap(int& x, int& y)
{
	int temp = 0;
	temp = x;
	x = y;
	y = temp;
}

void Sort(int array, size_t sizeOfArray)
{
	int i, j, min;
	for (i = 0; i < sizeOfArray - 1; i++ )
	{
		min = i;
		for(j = i + 1; j < sizeOfArray; j++)
			if(array[j] < array[min])
				min = j;
		if (min != i)
			Swap(array[i], array[min]);		
			
	}	
}
  
Last edited on
1
2
float Median(int numbers[]),size_t sizeOfArray)
                          ^
Thanks for pointing that out, but now its giving me a whole new slew of errors.
Line 40: [Error] 'sort' was not declared in this scope.
Line 69:[Error] invalid types 'int[int]' for array subscript.
Line 72: [Error] invalid types 'int[int]' for array subscript.

> Line 40: [Error] 'sort' was not declared in this scope.
case sensitive
your function is called `Sort'


> Line 69:[Error] invalid types 'int[int]' for array subscript.
> Line 72: [Error] invalid types 'int[int]' for array subscript.
You've got a typo in the signature of the function (line 62)
1
2
//void Sort(int array, size_t sizeOfArray) //what you've got, array is an int
void Sort(int *array, size_t sizeOfArray)
Topic archived. No new replies allowed.