Ok so I have an operator* for left scalar matrix multiplication that is correctly outputting for the first 4 outputs and not for the next 4.

If I have a matrix M2 with inputs [1,2;3,4;5,6;7,8] (the semicolon means next column), and multiplying it by 4, then I am getting the output:

I have no idea why it is doing it for the first half and not the second, here is my code below. Help is much appreciated.

template <class T>
matrix<T> operator*(const T & lh,const matrix<T> & rh) {
  matrix<T> result = rh;
  for (int i=0;i<rh.rows();i++) {   // .rows returns the number of rows
    for (int j=0;j<rh.cols();j++) {  // .cols returns the number of cols
      result.item(j,i) = lh * rh.item(i,j);  // item returns the item at (row,col)
    }   // j,i are switched here because otherwise it prints it incorrectly
  return result;  

I'd say there's probably something wrong with the rh.item matrix. Or switching the indecies is not the proper solution for your printing error.