parameter problem

so I making a linear sorting into a function and for some reason there is an error (Argument of type"int" is incompatible with type int) so here is my code:
note still don't get how to make the code block thing so I hope you guys can still read it.

Code{
#include <iostream>
#include <string>
using namespace std;

int sortAndSearch(int arr[])
{
for (int i = 0; i < 6; i++)
{
int smallestIndex = i;
for (int j = i + 1; j < 7; j++)
{
if (arr[j] < arr[smallestIndex])
{
smallestIndex = j;
}
}
int temp = arr[smallestIndex];
arr[smallestIndex] = arr[i];
arr[i] = temp;
}

// Print
for (int i = 0; i < 7; i++)
{
cout << arr[i] << ", ";
}
cout << endl;


}

int main()
{
int numbers[] = { 5, 9, 19, 6, 11, 15, 17 };

sortAndSearch(numbers[7]);

system("pause");
}

}code

so my error is by the main so I hope you can get the logic thanks in advanced.
When you pass in an array into a function, you only have to pass in the array name. What you are passing in is an element of the array.
sortAndSearch(numbers[7])
This passes in element 7 of the array which doesn't actually exist since the array goes from 0 - 6.

The parameter takes in an array not an integer. All you have to do is pass in the whole array.
sortAndSearch(numbers)

Hope this helps.
Kurisutofaa wrote:
The parameter takes in an array not an integer.

Just for completeness, the parameter is actually a pointer to an integer. In this case, it happens to be the first element of the array.

It's the same as having int sortAndSearch(int *arr) as the method signature.

still don't get how to make the code block thing

http://www.cplusplus.com/articles/z13hAqkS/
Topic archived. No new replies allowed.