hey guys i have done c++ program to overload operators for matrix. it works fine when i hard code the rows and cols. but when i take from the user it doesnt work. below is my code.. please help me
matrix matrix::operator*(matrix a)
{
matrix temp;
if(col!=a.row)
{
cout<<endl<"Cannot multiply these matrices!!!!";
return temp; //here temp row and col =0;
}
temp.row=row;
temp.col=a.col;
int k;
for(i=0;i<row;i++) {
for(j=0;j<col;j++){
temp.mat[i][j]=0; // for += use initialization
for(k=0;k<col;k++){ //you used row here
temp.mat[i][j]+=mat[i][k]*a.mat[k][j];
}
}
}
cout<<"\n the product of the two matices is:\n";
return temp;
}
matrix matrix::operator*(matrix a)
{
matrix temp;
if(col!=a.row)
{
cout<<endl<<"Cannot multiply these matrices!!!!";
return temp; //here temp row and col =0
}
temp.row=row;
temp.col=a.col;
int k;
for(i=0;i<temp.row;i++) {
for(j=0;j<temp.col;j++){
temp.mat[i][j]=0; // for += use initialization
for(k=0;k<col;k++){ //you used row here
temp.mat[i][j]+=mat[i][k]*a.mat[k][j];
}
}
}
cout<<"\n the product of the two matices is:\n";
return temp;
}