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

no one, nothing... is there something wrong with the way ive posted my question?

>>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)

Ok, whats the problem with this?

>>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?


not sure what you mean?


>>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

that void function adds matrices, so call it before you print out all the
result, like addMatrices(matrix1,matrix2,resultMatrix);
then you can print out the results.

>>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)

Ok, whats the problem with this?

>>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?


not sure what you mean?


>>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

that void function adds matrices, so call it before you print out all the
result, like addMatrices(matrix1,matrix2,resultMatrix);
then you can print out the results.

1) The format the user should be entering his matrice should be:
1 2 3 4 5 6 7 8 9 'ENTER'
right now it is 1 'ENTER', 2 'ENTER', 3 'ENTER' ... etc all the way to the 9th number.

2) if you look at the output I am currently getting at the bottom of my first post you will see that there is a '+' sign and an '=' sign after each row, i need to make it so that there is only 1 of each aligned with the center row.

3) thank you very much, i will work at that

[s]3) thank you very much, i will work at that[/s] (<-- supposed to be strike through)

fixed that one, thank you again!

>>1) The format the user should be entering his matrice should be:
1 2 3 4 5 6 7 8 9 'ENTER'
right now it is 1 'ENTER', 2 'ENTER', 3 'ENTER' ... etc all the way to the 9th number.

what happens if you just put 1 2 3 4 ... <enter> as your input, it should work.

2) if you look at the output I am currently getting at the bottom of my first post you will see that there is a '+' sign and an '=' sign after each row, i need to make it so that there is only 1 of each aligned with the center row.

so you want :

1 2 3      1 2 3     2 4 6 //and so on 
4 5 6  +  4 5 6  = 
6 7 9       7 8 9

if so then just do a test case(i.e if/else) when row is 2 and column is the last column.

if(row == 2 && col = lasCol)
   cout << A[i][j] <<" + " << endl;

for the other matrix you would have to change the plus to equal sign.


what happens if you just put 1 2 3 4 ... <enter> as your input, it should work.

it doesnt, it takes all 9 numbers as the first number for the 1st row of the 1st column of the 1st matrix

so you want :

1 2 3      1 2 3     2 4 6 //and so on 
4 5 6  +  4 5 6  = 
6 7 9       7 8 9

if so then just do a test case(i.e if/else) when row is 2 and column is the last column.

if(row == 2 && col = lasCol)
   cout << A[i][j] <<" + " << endl;

for the other matrix you would have to change the plus to equal sign.

aha!! makes sense, your a life saver

are you inputting it like this(exactly) :
input : 123456789
or are you putting it like this
input : 1 2 3 4 5 6 7 8 9

The seconds one should work.

:icon_redface:

BINGO!
that was the issue...

makes sense too, i guess if the numbers are grouped together then the software reads it as one #... with the spaces everything is good!

a thousand praises to you

Help me: how to join array a[1,2,3] and b[4,5,6] then become : c[1,2,3,4,5,6]

look up std::merge

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.