Click to See Complete Forum and Search --> : Run-Time Check Failure from Matrix Calculator


jbeith
January 21st, 2009, 02:55 AM
cout << "Enter Dimensions of first matrix" << endl;
cout << "Rows: ";
cin >> rows1;
cout << "Columns: ";
cin >> cols1;

cout << "Enter Dimensions of second matrix" << endl;
cout << "Rows: ";
cin >> rows2;
cout << "Columns: ";
cin >> cols2;

if(cols1 == rows2){
int matrix1[20][20];
int matrix2[20][20];
int matrix3[20][20];

cout << "MATRIX 1" << endl;
for(int i=0;i<rows1;++i){
for(int j=0;j<cols1;++j){
cout << "Enter value for Row ";
cout << i;
cout << ", Column ";
cout << j;
cout << ": ";
cin >> matrix1[i][j];
}
}
cout << "MATRIX 2" << endl;
for(int i=0;i<rows2;++i){
for(int j=0;j<cols2;++j){
cout << "Enter value for Row ";
cout << i;
cout << ", Column ";
cout << j;
cout << ": ";
cin >> matrix2[i][j];
}
}
cout << "CALCULATING..." << endl;
int x = 0;
for(int k=0;k<rows1;++k){
for(int i = 0;i<cols2;++i){
for(int j = 0;j<rows2;++i){
matrix3[k][i] += matrix1[k][j]*matrix2[j][i];
}
}
}


cout << "NEW MATRIX" << endl;
for(int i=0;i<rows1;++i){
for(int j=0;j<cols2;++j){
cout << matrix3[i][j];
cout << " ";
}
cout << "" << endl;
}

I get "Stack around the variable "***" was corrupted" for variables rows 1, rows 2, cols1, cols2, matrix1,matrix2.matrix3. Anyone know exactly it's having problems with in it?

darwen
January 21st, 2009, 08:00 PM
Debug through and watch the variables.

If you don't know how to use the VS debugger learn it now.

We have one of the best debuggers ever produced for any platform with the VS IDE, so it's a crime not to use it.

Also use of the debugger is an essential piece of knowledge for development - even though most courses don't teach it.

Darwen.