Right here:
char tempfn=fn[100][14];
fn is an array 100*14. By assigning tempfn to element 100 (the 101st element in the sequence) and element 14 (the 15th element in the sequence) you are stepping out of bounds of the array.
I've just also noticed that before that, in the function header, you have
char fn[100][14]
which may cause some problems.
What I would do to organize data would be to make a structure containing net pay and names.
1 2 3 4 5 6
|
struct Employee
{
float net;
char fn[14];
char ln[15];
} Employees[100];
|
Now you could pass just the structure into your
findorder
function and then you only need to sort one time, not once for each of your entries.
example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
void findorder(Employee list[], int n) // n represents the number of elements to sort,
{
bool out_of_order = true;
while (out_of_order) {
out_of_order = false;
for (int i=0; i < n-1; i++) {
if (list[i].net > list[i+1].net) {
out_of_order = true;
Employee temp = list[i];
list[i] = list[i+1];
list[i+1] = temp;
}
}
}
}
|
Granted this code is not the most efficient ordering algorithm, nor does it return the array back to the main function. But it does display how much easier it is to sort a structure than 3 parallel arrays.
Now, if I were to make minimal changes to your function, I notice that you seem to order each array independantly. This means that they will all be in their own orders from lowest value to highest which means the names and net pay will not correlate. If you want to sort by net pay, then do the
if (net[p]<net[p-1]){
condition and then swap all three arrays in that if statement. This means that you should not use
if (fn[p]<fn[p-1]){
or
if (ln[p]<ln[p-1]){
.