Yes, I'm looking through the rest of the code now.
The thing to do is to have the program driven by whatever it finds in the file, that is don't assume there will be 10 entries.
This will affect the way that you read the data into the array, but it also affects all the rest of the program too, you will need to get rid of hard-coded numbers such such as 8, 9 and 10 (except perhaps at the very start).
Instead of this:
1 2 3 4 5 6 7 8
|
ifstream InputFile;
InputFile.open("CSC2144N.txt");
for (int counter=0;counter <= 9;counter++)
{
InputFile >> entry.num[counter];
InputFile >> entry.fnum[counter];
cout << entry.num[counter] << setw(9) << entry.fnum[counter] << endl;
}
|
You might have something like this:
1 2 3 4 5 6
|
int count = 0;
ifstream InputFile("CSC2144N.txt");
while (count < 10 && InputFile >> entry.num[count] >> entry.fnum[count])
{
count++;
}
|
Then the first option would look like this:
1 2 3 4 5 6 7
|
if (menu == 1)
{
for (int i=0; i < count; i++)
{
cout<< setw(9) << entry.num[i] << setw(9) << entry.fnum[i] << endl;
}
}
|
When it comes to the sorting, remember to use the
count
variable to set the limit of each loop (as appropriate). Also, you will need to swap both member variables.
Each time a pair of integers are exchanged, you need to do a corresponding swap of the pair of floats. Otherwise the pairs become mismatched, half of one pair being matched with the other half of some completely unrelated pair.