when i compile i get an error message saying the following
"51: error: assignment of read-only location"
line 51 reads: c[j] = a[j] + b[j];
any help to get rid of this problem???
#include <iostream>
#include <iomanip>
using namespace std;
#define N 3
void addMatrix(const double a[][N],
const double b[][N], const double c[][N]);
int main()
{
double a[N][N];
double b[N][N];
double c[N][N];
// Enter nine digits for matrix 1
cout << "Enter matrix1: ";
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
cin >> a[i][j];
}
// Enter nine digits for matrix 2
cout << "Enter matrix2: ";
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
cin >> b[i][j];
}
for(int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
c[i][j] = 0;
}
addMatrix(a,b,c);
return 0;
}
void addMatrix(const double a[][N],
const double b[][N], const double c[][N])
{
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
c[i][j] = a[i][j] + b[i][j];
}
cout << " The multiplication of the matrices is " << endl;
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
cout << a[i][j];
if(i == 0)
cout << setw(3);
else if(i == 1)
cout << setw(3) <<"+" << setw(3);
else if(i == 2)
cout <<setw(3);
for (int j = 0; j < N; j++)
cout << b[i][j];
if(i == 0)
cout << setw(3);
else if(i == 1)
cout << setw(3) <<"+" << setw(3);
else if(i == 2)
cout <<setw(3);
for (int j = 0; j < N; j++)
cout <<c[i][j];
cout << endl;
}
}