Issue with 2D Array/increment

Hey guys, I'm trying to store a "Difference Index" within a 2D array. The rest of the code works fine except for this part below. The error is directly related to Mstorage, and MstorageCount and FstorageCount.

I'm getting an error that is essentially saying "that there is NULL"

here's the error code: "Unhandled exception at 0x58771f68 (msvcp100d.dll) in PROJECT 6.exe: 0xC0000005: Access violation reading location 0x00000008."

and so it crashes, however, it will work if I take out the 2D array, and it will work fine is I keep the 2D array in the code, but don't increment or decrement and instead use a static value. Can some one help me solve the issue? If anyone wants more of the code, I'll provide it.

Here is the segment:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
	int Mdifference[15];
	int MfinalDifference = 0;
	int MtempDifference = 0;
	int Mstorage[MAXARRAY][MAXARRAY];
	int MstorageCount = 0, FstorageCount = 0;
	for(int count1 = 0; count1 < maleCount; count1++)
	{
		for(int count2 = 0; count2 < femaleCount; count2++)
		{
			for(int count = 0; count < 10; count ++)
			{
				
				Mdifference[count] = labs(male[count1].scores[count] - female[count2].scores[count]);
				MfinalDifference += Mdifference[count];
			}
			Mstorage[MstorageCount][FstorageCount] = MfinalDifference;
			MstorageCount++;
			FstorageCount++; 
			cout << male[count1].name << " and " << female[count2].name 
				<< " have a diference index of: " << MfinalDifference - MtempDifference << endl;
			MfinalDifference = MtempDifference;

		}
				
	}
	cout << "\n\nBREAK\n\n";

	for(int count1 = 0; count1 < maleCount; count1++)
	{
		for(int count2 = 0; count2 < femaleCount; count2++)
		{
			cout << Mstorage[maleCount][femaleCount] << ' ';
		}

		cout << endl;	
	}
The way you use them, MstorageCount and FstorageCount will both be incremented up to
malecount*femalecount.

According to your display code, I think you should replace lines 16 to 18 by
Mstorage[count1][count2] = MfinalDifference;
Okay, Thank you, that has definitely allowed the entire code to execute, however, now, when I try to print out the values,below 'BREAK' , I am just getting "-858993460" for all the values, somehow it isn't storing.
The problem comes from your display code.
It should be cout << Mstorage[count1][count2] << ' ';
Wow... Thank you. Tonight, toum, your my hero. I appreciate the help sir!
Topic archived. No new replies allowed.