0

Hi, I have to build a matrix class with functions that you would expect, Im wondering if anyone can tell me why one or both of these functions arent working correctly? Basically a test harness is run against them to check so the data is random. Im sure it is most likely something simple but I thought I had it correct. Thanks in advance for anyone who takes the time to look this over. :)

.h

```
#ifndef __MATRIX_H__
#define __MATRIX_H__
class CMatrix
{
public:
float m_fMatrix[4][4];
};
#endif // __MATRIX_H_
```

Set identity matrix.

```
void
CExercises::SetIdentity(CMatrix& _rResult)
{
// Implement your logic here:
for(int i = 0; i < 4; ++i)
{
for(int j = 0; j < 4; ++j)
{
_rResult.m_fMatrix[i][j] = 0;
if((i == 1) && (j == 1))
{
_rResult.m_fMatrix[i][j] = 1;
}
if((i == 2) && (j == 2))
{
_rResult.m_fMatrix[i][j] = 1;
}
if((i == 3) && (j == 3))
{
_rResult.m_fMatrix[i][j] = 1;
}
if((i == 4) && (j == 4))
{
_rResult.m_fMatrix[i][j] = 1;
}
}
}
}
```

multiply matrix function.

```
void
CExercises::Multiply(const CMatrix& _rLHS, const CMatrix& _rRHS, CMatrix& _rResult)
{
// Implement your logic here:
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
float temp = 0;
for (int k = 0; k < 4; k++)
{
temp += _rRHS.m_fMatrix[i][k] * _rLHS.m_fMatrix[k][j];
}
_rResult.m_fMatrix[i][j] = temp;
}
}
}
```