What I am trying to do is to a variable in an array after sorting (ascending order) it through a function.
The function I have is:
void xpPoints_Sorting ()
{
int xpPoints[] = { 620, 500, 250, 1000, 830, 100, 370 };
int temp;
for(int i=1;i< 7;++i)
{
for(int j=0;j<(7-i);++j)
if(xpPoints[j] > xpPoints[j+1])
{
temp = xp[j];
xpPoints[j] = xpPoints[j+1];
xpPoints[j+1] = temp;
}
}
}
The problem is that when I type xpPoints[0], in int main(), the output is still "620" and not "100".
int main()
{
xpPoints_Sorting ();
int xpPoints[] = { 620, 500, 250, 1000, 830, 100, 370 };
cout << xpPoints[0];
}
However, when I take I don't put it in a function and put it in int main(), it works perfectly fine and outputs "100".
How can I get it to work while keeping the function for sorting the array?
xpPointsis local to main isnt't it? where you passed array to function?mainandxpPoints_Sorting?