Exception throw error

Exception thrown at 0x0F7D40DA

this code works fine,first matrix 3x3 and second matrix 3x2 it give expection error at second matrix when i give some values to it
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include<iostream>
using namespace std;

int main()
{

	int row, col, row1, col1, store, temp, **arr, **arr1, **arr2 = NULL;
	row = col = row1 = col1 = store = temp = 0;

	cout << "\nFirst Matrix\n";

	cout << "\nEnter The Row : ";
	cin >> row;
	cout << "\nEnter The Col : ";
	cin >> col;

	cout << "\nSecond Matrix\n";

	cout << "\nEnter The Row : ";
	cin >> row1;
	cout << "\nEnter The Col : ";
	cin >> col1;

	if ((col == row1))
	{
		arr = new int*[row];
		arr1 = new int*[row1];
		arr2 = new int*[row];

		for (int i = 0; i < col; i++)
			arr[i] = new int[col];
		for (int i = 0; i < col1; i++)
			arr1[i] = new int[col1];
		for (int i = 0; i < col1; i++)
			arr2[i] = new int[col1];

		// error first matrix 3x3 and second 3x2

		cout << "\nFirst Matrix input\n";
		for (int i = 0; i < row; i++)
		{
			for (int j = 0; j < col; j++)
			{
				cin >> arr[i][j];
			}
		}
		cout << "\nSecond Matrix input\n";
		for (int i = 0; i < row1; i++)
		{
			for (int j = 0; j < col1; j++)
			{
				cin >> arr1[i][j]; // getting expection error at this line
			}
		}

		for (int i = 0; i < row; i++)
		{
			for (int j = 0; j < col1; j++)
			{
				store = (arr[i][j] * arr1[j][temp]) + store;
				if (temp == col1)
					break;
				else if (j == col1 - 1)
				{
					arr2[i][temp] = store;
					temp++;
					store = 0;
					j = -1;
				}
				else
					continue;
			}
			temp = 0;
			store = 0;
		}
	}
	else
	{
		cout << "\nProduct Of these matrices are undefined\n";
	}
	if (arr2 == NULL)
		return;
	else
	{
		cout << "\nProduct Of These Two Matrices\n";
		for (int i = 0; i < row; i++)
		{
			for (int j = 0; j < col1; j++)
			{
				cout << arr2[i][j] << " ";
			}
			cout << endl;
		}
	}
}
  


error pic
http://oi65.tinypic.com/1zn6eqo.jpg

Last edited on
1
2
3
arr = new int*[row];
for (int i = 0; i < col; i++)
	arr[i] = new int[col];
you allocate `row' elements, but you traverse `col' cells.
Last edited on
Sorry i did not get you what are you trying to say
1
2
arr = new int*[row];
for (int i = 0; i < col; i++)
do a desk check.
Topic archived. No new replies allowed.