SIGSEGV Error, return value 3221225477

Hello, I am a beginning programmer and I am having a problem with my program. My program is suppose two create two matrices and multiply them together. I got the creating to matrices portion down and I believe I have the multiplication function down too however that portion crashes my program. When I debug it I get a SIGSEGV error and I was wondering if you guys can take a look and see what is causing it. Thanks in advance

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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
  #include<vector>
#include<iostream>
 
using namespace std;
 
int aRowSize, aColSize,bRowSize, bColSize; //creates column and row size
int aValue, bValue; //stores AN input for a row and column
vector<int> aTemp, bTemp; //stores each input in value and puts it in a vector
vector<int> colA, rowA, colB, rowB; //stores row# and column# size for matrix
vector< vector<int> > matrixA; vector< vector<int> > matrixB; //vector that stores the value of each row and column
 
int multiply_matrices();
 
int main(){    
               
       
        cout << "This program will create two matrices and muliply them together \n"
                 << "=============================================================== \n";
/* Creates dimension for matrix */
        cout <<"Enter the row size of matrixA: "<<endl;
        cin >>aRowSize;
        cout <<endl;
        cout <<"Enter the column size of matrixA: "<<endl;
        cin >>aColSize;
        cout <<endl;
        cout <<"Enter the row size of matrixB: "<<endl;
        cin >>bRowSize;
        cout <<endl;
        cout <<"Enter the column size of matrixB: "<<endl;
        cin >>bColSize;
        cout <<endl;
       
/* Creates matrixA*/   
        for (int i = 0; i <= aRowSize-1; i++)
    {
        for(int j = 1; j <= aColSize; j++)
        {
            cout << "For matrixA, enter the value of row " << (i+1) << ", column " << (j) << ": ";
            cin >> aValue;          
                        aTemp.push_back(aValue);  
                         
        }
                matrixA.push_back(aTemp);
                aTemp.clear();
        }
        cout << endl;
/* Creates matrixB*/
       
        for (int i = 0; i <= bRowSize-1; i++)
    {
        for(int j = 1; j <= bColSize; j++)
        {
            cout << "For matrixB, enter the value of row " << (i+1) << ", column " << (j) << ": ";
            cin >> bValue;
           
                        bTemp.push_back(bValue);  
                         
        }
                matrixB.push_back(bTemp);
                bTemp.clear();
        }
       
       
/*results for matrixA */
        cout <<"Your matrixA is: "<<endl;
        for (int i = 0; i < aRowSize; i++)
    {
        for(int j = 0; j < aColSize; j++)
        {
                cout<<matrixA[i][j]<< " ";
        }
        cout <<endl;
    }
/*results for matrixB*/
    cout <<"Your matrixB is: "<<endl;
        for (int i = 0; i < bRowSize; i++)
    {
        for(int j = 0; j < bColSize; j++)
        {
                cout<<matrixB[i][j]<< " ";
        }
        cout <<endl;
    }
    multiply_matrices();
}
 
int multiply_matrices()
{
        int i, j, k;
        vector< vector<int> > matrixC;
        if (colA != rowB)
        {
      cout << "incompatible dimensions";
        }
       
                else                                                                            //ERROR OCCURS HERE
                {      
                for (i=1; i <aRowSize; i++)  
                        {
                        for (j=1; j <bColSize; i++)
                        {
                        matrixC[i][j] =0;
                                for(k = 1; i<aColSize;i++)
                                        {
                        matrixC[i][j]=matrixC[i][j] + matrixA[i][k] * matrixB[k][j];
                        }
                        }                                                                       // TO HERE
       
                }
                }
                for (int i = 0; i < aRowSize; i++)
                {
                for(int j = 0; j < bColSize; j++)
                        {
                                cout<<matrixC[i][j]<< " ";
                        }
                        cout <<endl;
                }
               
}
Error is on lines 90 and 102. How many elements does your matrixC have?
It should have the same amount as aRowSize and bColSize.
So I should change the 0 value?
I changed it so it shows the size but the program is still crashing

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
int multiply_matrices()
{
	int i, j, k;
	vector< vector<int> > matrixC(aRowSize, vector<int>(bColSize));
 	if (colA != rowB)
	{
      cout << "incompatible dimensions";
  	}
  	
		else
		{	
      		for (i=1; i <aRowSize; i++)  
			{
        		for (j=1; j <bColSize; j++) 
        		{
            		matrixC[i][j]= 0;
         			for(k = 1; i<aColSize;k++)
					{
              		matrixC[i][j]=matrixC[i][j] + matrixA[i][k] * matrixB[k][j];
              		}
    			}
  	
    		}
		}
		for (int i = 0; i < aRowSize; i++)
    		{
        	for(int j = 0; j < bColSize; j++)
        		{
        			cout<<matrixC[i][j]<< " ";
        		}
        		cout <<endl;
    		}
    		
}
Last edited on
What are you doing on line 5?
Topic archived. No new replies allowed.