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:
#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;
}
There also shouldn't be 2 topics about essentially the same subject. There is a risk that the same things will be said in both, possibly making it a time waster for those who reply.