Hello all, i am looking for a little help but PLEASE do not solve the problem for me, i need to learn the stuff. Below are a list of problems i am having, followed by my code and then the output i currently have
my problems:
1) the style in which the user inputs their numbers for each 3x3 matrix should be - enter all 9 #s and then press enter... as opposed to enter a # press enter (9x)
2) the only place i know where to put the '+' and '=' sign makes it print each time... where should i place it to only print in the center of the Matrices?
3) part of the assignment is to use the void function, i never utilize it in my main, im lost as to where exactly i should put it in
#include <iostream>
using namespace std;
#define N 3
void addMatrix(const double a[][N], const double b[][N], double c[][N]);
int main()
{
int i = 0;
int j = 0;
const int ROW = 3;
const int COLUMN = 3;
double a[ROW][COLUMN];
double b[ROW][COLUMN];
double c[ROW][COLUMN];
cout << "Enter 1st 3x3 Matrix:" << endl;
for (int i = 0; i < ROW; i++)
{
for (int j = 0; j < COLUMN; j++)
{
cin >> a[i][j];
}
}
cout << "Enter 2nd 3x3 Matrix:" << endl;
for (int i = 0; i < ROW; i++)
{
for (int j = 0; j < COLUMN; j++)
{
cin >> b[i][j];
}
}
cout << "The sum of both Matrices is:" << endl;
for (int i = 0; i < ROW; i++)
{
for (int j = 0; j < COLUMN; j++)
{
cout << a[i][j] << " ";
}
cout << "+ ";
for (int j = 0; j < COLUMN; j++)
{
cout << b[i][j] << " ";
}
cout << "= ";
for(int j = 0; j < COLUMN; j++)
{
c[i][j] = a[i][j] + b[i][j];
cout << c[i][j] << " ";
}
cout << endl;
}
return 0;
}
void addMatrix(const double a[][N], const double b[][N], 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];
}
}
}
and the output
The sum of both Matrices is:
1 2 3 + 1 2 3 = 2 4 6
4 5 6 + 4 5 6 = 8 10 12
7 8 9 + 7 8 9 = 14 16 18