Line 19 is outside of the loop, so if numval is 6 then this is what the code does:
1 2 3 4
for(int i = 0; i < numval; i++) { // loop 6 times
cin >> array[i]; // entering the 6 values into array
}
PrintArray(array, numval); // then print the array once
You need to write the selection sort algorithm. Insert calls to PrintArray inside the algorithm at the appropriate spots.
If you have a working selection sort function and your print function then you have all you need.
A selection sort has two loops: outer loop and inner loop. The inner loop selects the next element in the unsorted elements. The outer loop continues until there are no unsorted elements.
So, you should simply call the print function at the end of the outer loop.
I have it almost working, but I need it to print the final result number of numbers-1 times, and it's only printing it until it gets the correct result:
call PrintArray(array, track); after sorting work finished.
or write printing code in main().
i.e. you made a function call for 3 line printing algo, but not for more lengthy sorting algo ! call for both or do both in main()