I think there's something to do with the rest of the program:
Code:
#include <iostream>
#include <fstream>
using namespace std;
ifstream file_in;
const int SIZE = 25;
void readdata (int [], int [], int &);
void printdata (int [], int [], int);
void lsort (int [], int [], int);
void bsort (int [], int [], int);
int main () {
int n, ans, ans2;
int idnumbers [SIZE];
int scores [SIZE];
file_in.open ("program6in.dat");
readdata (idnumbers, scores, n);
cout << "The 2 arrays:" << endl;
printdata (idnumbers, scores, n);
lsort (idnumbers, scores, n);
cout << "The linear sorted arrays:" << endl;
printdata (idnumbers, scores, n);
cout << "The Bubble sorted arrays: " << endl;
printdata (idnumbers, scores, n);
system ("pause");
return 0;
}
void readdata (int idnumbers [], int scores [], int &n)
{
file_in >> n;
for (int count = 0; count < n; count++) {
file_in >> idnumbers [count];
file_in >> scores [count];
}
return;
}
void printdata (int idnumbers [], int scores [], int k)
{
for (int count = 0; count < k; count++) {
cout << idnumbers [count] << " ";
cout << scores [count] << endl;
}
return;
}
void lsort (int idnumbers [], int scores [], int n)
{
int temp, temp2;
for (int pass = 0; pass < n - 1; pass++)
for (int count = pass + 1; count < n; count++) {
if (idnumbers [count] > idnumbers [pass]) {
temp = idnumbers [count];
idnumbers [count] = idnumbers [pass];
idnumbers [pass] = temp;
temp2 = scores [count];
scores [count] = scores [pass];
scores [pass] = temp2;
}
}
return;
}
void bsort (int scores [], int idnumbers [], int n)
{ int temp, temp2;
bool swapped;
do {
swapped = false;
for (int pos = 0; pos < n - 1; pos++) {
if (scores [pos] > scores [pos + 1]) {
temp = scores [pos];
scores [pos] = scores [pos + 1];
scores [pos + 1] = temp;
temp2 = idnumbers [pos];
idnumbers [pos] = idnumbers [pos + 1];
idnumbers [pos + 1] = temp2;
swapped = true;
}
}
}
while (swapped);
return;
}
And this is my output:
Code:
The 2 arrays:
123 1450
124 2400
321 1200
246 1100
345 820
The linear sorted arrays:
345 820
321 1200
246 1100
124 2400
123 1450
The Bubble sorted arrays:
345 820
321 1200
246 1100
124 2400
123 1450
Press any key to continue
. . .
They are identical, I don't know why
The numbers on the left are supposed to be in descending order, the ones on the right, ascending, and always matched up with each other