I'm trying to add and print two matrices and get the sum by using 2-Dimensional Arrays.
I have to read in 18 numbers from a file.
My txt file includes:
1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3
Currently, my program will come up, but I do not see anything on the screen. I get a popup error.
Here is my code:
#include <iostream>
#include <fstream>
using namespace std;
const int ROWS = 3;
const int COLS = 3;
int main ()
{
ifstream inData;
cout<<fixed<<showpoint;
cout.precision(2);
inData.open ("Test.txt");
int firstmatrix[ROWS][COLS] = {1,1,1,1,1,1,1,1,1};
int secondmatrix[ROWS][COLS] = {3,3,3,3,3,3,3,3,3};
int sum;
inData>>firstmatrix[ROWS][COLS]>>secondmatrix[ROWS][COLS];
for (int i = 0; i<3; i++)
{
sum = 0;
for (int j=0; j<3;j++)
{
sum = (firstmatrix[ROWS][COLS] + secondmatrix[ROWS][COLS]);
cout<<firstmatrix[i][j]<<" + "<<secondmatrix[i][j]<<" = "<<sum<<endl;
}
}
inData.close();
system ("PAUSE");
return 0;
}