Bubble sort fix

Will someone please take a look at this and give me an idea of why my sort function isn't working? My assignment is already past due but at this point I really want to know how to do it because this this has been the death of me all week. my total hours are calculated in each row during the first function and fed back to the array in the main and held in the 8th element aka arr[][7] for each row. taking that and passing it into a bubble sort function was the next step. i thought I had it but every time it runs, i get back errors. what am i missing? thank you




#include<iostream>
#include<string>
#include<fstream>
#include<cstdlib>
#include<iomanip>
#include<sstream>

using namespace std;

int const TTL_HRS = 7;
void getData(int arr[][8], string name[50], int length);
void bubbleSort(int arr[][8], string name[50], int length);

int main() {

int arr[50][8];
arr[0][TTL_HRS];
string name[50];
getData(arr, name, 50);
bubbleSort(arr, name, 50);

system("pause");
}

void getData(int arr[][8], string name[50], int length) {

ifstream fin;
fin.open("empdata2.txt");
int i;
fin >> i;

if (fin.fail()) {
cout << " Your file was unable to open.\n\n";
exit(1);
}
arr[50][8];
name[50];
int total = 0;
for (int row = 0; row < i; ++row) {
fin >> name[row];
cout << name[row] << " ";

total = 0;

for (int day = 0; day < 7; day++) {
fin >> arr[row][day];
total += arr[row][day];


cout << setw(3) << arr[row][day];

}

cout << setw(3) << total << endl;
cout << endl;

}
fin.close();

}void bubbleSort(int arr[][8], string name[50], int length)
{
int total = arr[0][7];

for (int i = 0; i<50 - 1; i++)
{
for (int j = 0; j<8 - 1; j++)
{
//if(array[j+1][0] < array[j][0]) // swap values
if (arr[j + 1] > arr[j])
{
swap(arr[j], arr[j + 1]);
swap(name[j], name[j + 1]);
}
}
}

return;

}
Last edited on
Can you show us the contents of the file "empdata2.txt"? That would be helpful.
of course. the file reads in with the first function like so..
output =
Cat,Bill 9 3 7 5 8 0 0 32

Snake,Frank 2 3 8 3 6 3 5 30

Dog,Chet 8 8 3 0 8 2 0 29

Mouse,Mickey 9 10 4 7 0 0 0 30

Duck,Daffy 5 6 5 6 5 6 5 38

Mouse,Minnie 7 3 8 7 2 5 7 39

Yosimitee,Sam 2 5 3 0 4 9 4 27

Press any key to continue . . .



eventually it needs to look like so

Employee Weekly Hours:
Name: S M T W T F S TTL
Mouse, Minnie 7 3 8 7 2 5 7 39
Duck, Daffy 5 6 5 6 5 6 5 38
Cat, Bill 9 3 7 5 8 0 0 32
Snake, Frank 2 3 8 3 6 3 5 30
Mouse, Mickey 9 10 4 7 0 0 0 30
Dog, Chet 8 8 3 0 8 2 0 29
Yosimitee, Sam 2 5 3 0 4 9 4 27

Last edited on
Update: I have updated what i have added to the code and where i am at in it. please give any feedback would be great. my assignment was due this morning and my teacher does not accept late work so at this point it is more for my satisfaction to know what the program is that defeated me.
Topic archived. No new replies allowed.