2-D array and Printing name

So, basically, everything works fine in my code except for printing out the female matches name. "j" represents the spot in the array of the females name. I know, that if I use j-1 for example, it will only print the last female name in the array, which is incorrect. I need to print the correct corresponding name, so I added in "k", which is supposed to be subtracted from "j", from there I could modify K to reflect the proper results, and it works fine until the third match is printing out, where it freezes up and crashes before printing out the female match name. I'm assuming that this is because somehow Im getting a value that is not in the array.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
	int j;
	int k = 0;
		for(int i = 0; i < maleCount; i++)
		{
			for(j = 0; j < femaleCount;j++)
			{
				int temp;
				if(Mstorage[i][j] < Mstorage[i][j+1])  
					{
						temp = Mstorage[i][j];
						Mstorage[i][j] = Mstorage[i][j+1];
						Mstorage[i][j+1] = temp;
						k++;
					}
				
			}
			cout << male[i].name << setw(24-male[i].name.length()) << "|" << female[j-k].name << ' ' << Mstorage[i][j-1];
			cout << endl;
		}
Topic archived. No new replies allowed.