My program needs to take the first 5 numbers from a file, sort them and print them out. Then take the next 5 numbers and sort just those 5 numbers and print them out. However, when I try to sort them independently it is sorting them all together as if I wanted all 10 to be sorted. The first sort is fine because it only deals with the first 5 numbers, but the second sort that I try to do includes the previous numbers too and I cannot figure out why. Can anyone help me please? Here is my code.
while (!in_stream.eof())
{
for(int i=0; i<5; i++)
{
in_stream >> arrayOne[linecount];
sum += arrayOne[linecount];
average += arrayOne[linecount]/5;
selectionSort(arrayOne,5);
}
for (int i = 0; i < 5; i++)
{
cout << arrayOne[i] << " ";
out_stream << arrayOne[i] << " ";
}
out_stream << "sum= " << sum << " " << "average= " << setprecision(4) << average << endl;
cout << "sum= " << sum << " " << "average= " << setprecision(4) << average << endl;
///////////////////////////////////////////////////////////////////////////////////
for(int i=5; i<10; i++)
{
in_stream >> arrayOne[linecount];
sum2 += arrayOne[linecount];
average2 += arrayOne[linecount]/5;
selectionSort(arrayOne,5);
}
for (int i = 0; i < 5; i++)
{
cout << arrayOne[i] << " ";
out_stream << arrayOne[i] << " ";
}
out_stream << "sum= " << setprecision(3) << sum3 << " " << "average= " << setprecision(3) << average3 << endl;
cout << "sum= " << setprecision(5) << sum2 << " " << "average= " << setprecision(4) << average2 << endl;