how can user input matrix row by row ?

Hi , I hope you could help by today

Actually question is about entering to matrices , add , subtract and multiply them
I didn't now how to do this point
*******************
ask the user to enter data for matrices, such as:
Row#? Data for first matrix: _ (separated by commas)
. (figure out data in each column automatically from the row data)
Row#? Data for second matrix: _ (separated by commas)
. (figure out data in each column automatically from the row data)
If the user enter incorrect amount of data in any row, generate error message and ask
user for correct amount of data.
***************************************
?
please answer :(
show what code you've done so far.
/*
----------------------------------
This program compute the addition , subtraction
and multiplication for two 2D array */

#include <iostream>
using namespace std;
int main()
{
int operation,row1,column1,row2,column2 ;
int matrix1 [100][100] , matrix2 [100][100] , addition[100][100] , subtraction [100][100] , multiplication [100][100] ;

// Display the menu of operations
cout << "Menu of operations " << endl ;
cout << "-------------------------" << endl ;
cout << "1- MATRIX ADDITION" << endl ;
cout << "2- MATRIX SUBTRACTION" << endl ;
cout << "3- MATRIX MULTIPLICATION" << endl ;
cout << "-------------------------" << endl ;

cout << "Please enter your choice from the menu above : " ;
cin >> operation ;

// Display Error message if user enter not availble
// number of operation and ask him to enter again
if (operation < 1 || operation > 3 )
{
cout << "Error! Please enter a number avalible in menu above" << endl;
cin >> operation ;
}

// Ask the user about the size of each matrix
cout <<"How many rows are in the first matrix ? " ;
cin >> row1 ;
cout <<"How many columns are in the first matrix ? " ;
cin >> column1 ;
cout <<"How many rows are in the second matrix ? " ;
cin >> row2 ;
cout <<"How many columns are in the second matrix ? " ;
cin >> column2 ;
cout << endl ;

matrix1 [row1][column1] ;
matrix2 [row2][column2] ;

// Check the conditions which must be satsified to perform the operation
switch (operation)
{
case 1 :
{
if (row1 != row2 || column1 != column2 )
{
cout << "Error ! Number of rows/columns in matrix 1 must be equal to " << endl <<
"Number of rows/columns in matrix 2 to preform ADDITION" << endl << endl ;
system ("pause");
return -1 ;
}

break;
}
case 2 :
{
if (row1 != row2 || column1 != column2 )
cout << "Error ! Number of rows/columns in matrix 1 must be equal to " << endl <<
"Number of rows/columns in matrix 2 to preform SUBTRACTION" << endl << endl ;
system ("pause");
return -1 ;
}
case 3 :
{
if ( column1 != row2 )
cout << "Error ! Number of Columns in first matrix must be equal " << endl <<
"to number of rows in second matrix to prefom Multiplication" << endl << endl;
system ("pause");
return -1 ;
break;
}
}
// Ask user to enter first marix
cout << "First Matrix :" << endl ;

for(int i=0; i<row1; i++)
{ cout << "Please enter row #" << i+1 << " : " ;
{
for (int j=0; j<column1; j++ )
cin >> matrix1 [i][j] ;
}
}
cout << endl ;

// Ask user to enter Second marix
cout << "Second Matrix :" << endl ;

for(int i=0; i<row2; i++)
{ cout << "Please enter row #" << i+1 << " : " ;
{
for (int j=0; j<column2; j++ )
cin >> matrix2 [i][j] ;
}
}
cout << endl ;
switch(operation)
{
case 1 :
// Prefprm ADITION
for (int i=0 ; i<row1 ; i++)
for (int j=0; j<column1 ; j++)
{
addition[i][j]= matrix1 [i][j] + matrix2 [i][j] ;
cout << addition[i][j] << endl ;
}
break ;

case 2 :
// preform SUBTRACTION
for (int i=0 ; i<row1 ; i++)
for (int j=0; j<column1 ; j++)
{
subtraction[i][j]= matrix1 [i][j] - matrix2 [i][j] ;
cout << subtraction[i][j] << endl ;
}
break ;

case 3 :
// preform MULTIPLICATION
for (int i=0 ; i<row1 ; i++ )
for ( int j=0 ; j<column2 ; j++ )
for ( int k=0 ; k<column2 ; k++ )
{
multiplication[i][j] += matrix1[i][j] * matrix2 [i][j] ;
cout << multiplication [i][j] ;
}
break ;

}
system ("pause") ;
return 0 ;
}
Topic archived. No new replies allowed.