#include <iostream>
#include <fstream>
#include "matrix.h"
using namespace std;

int main() {

  ifstream fin;

  do {
    if (fin.fail()) {
      cout << "Unable to open file." << endl;
      fin.clear();
    }
    string filename;
    cout << "Enter filename containing origin matrix: ";
    cin >> filename;
    fin.open(filename.c_str());
  } while (fin.fail());

  matrix A;
  fin >> A;

  cout << "Matrix A was read as:" << endl;
  cout << A << endl;

  bool quit = false;
  while (!quit) {
    int r,c;
    float val;
    
    cout << "Ready to test assignment." << endl;
    cout << "Enter a row index (or -1 to quit): ";
    cin >> r;
    if (r < 0)
      quit = true;
    else {
      cout << "Enter a column index: ";
      cin >> c;
      cout << "Enter a value: ";
      cin >> val;

      A(r,c) = val;

      cout << "Updated matrix is:" << endl;
      cout << A << endl;
    }
  }
}
