Array Sorting Error

I have finished my code which is used to sort an array, however I continuously am getting an error on line 44 saying "error: expected primary-expression before ']' token".

Can someone please help me in figuring out what I am doing wrong?
The code is below:


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
#include <iostream>
using namespace std;

//sorting the array
void sort(int num[])
{
int temp;
for (int i2=0; i2<=4; i2++)
{
for (int j=0; j<4; j++)
{
//swaping elements here
if (num[j]>num[j+1])
{
temp = num[j+1];
num[j+1]=num[j];
num[j]=temp;
}
}
}
cout << "\nHere is the ascending order of the array\n";
for (int k=0; k<5; k++)
{
cout << k << ".\t" << num[k] << endl;
}
cout << endl;
}

int main()
{
int num[5];
for (int i=0; i<5; i++)//loop to read/populate/load the array
{
cout << "Please enter the number: ";
cin >> num[i];
}
cout << endl;
cout << "\nHere are the ORIGINAL VALUES of the array\n";
for (int j=0; j< 5; j++)//loop tp print the ORIGINAL VALUES OF THE ARRAY
{
cout << j << ".\t" << num[j] << endl;
}
cout << endl;
sort(num[]);
return 0;
}
Last edited on
sort(num[]);
When passing an array to a function you can't use [].
This should work sort(num);
That did work. Thank you!!
Topic archived. No new replies allowed.