#include <iostream>
#include <cstdlib>
#include <iomanip>
usingnamespace std;
char menu(char);
int main()
{
int row, col;
float A[row][col], B[row][col], C[row][col];
char op, select;
cout << "Welcome!";
cout << "\nEnter 2 numbers for the row and column of the matrices:"
<< "\n(Space in between) ";
cin >> row >> col;
cout << "Input Matrix A values: ";
for(int b = 0; b < row; b++)
{
for(int e = 0; e < col; e++)
{
cin >> A[b][e];
}
}
cout << "Input Matrix B values: ";
for(int b1 = 0; b1 < row; ++b1)
{
for(int e1 = 0; e1 < col; ++e1)
{
cin >> B[b1][e1];
}
}
do
{
select = menu(op);
if(select == '?')
{
menu(op);
}
if(select == 'i')
{
cout << "\nEnter 2 numbers for the row and column of the matrices:"
<< "\n(Space in between) ";
cin >> row >> col;
cout << "Input Matrix A values: ";
for(int b = 0; b < row; ++b)
{
for(int e = 0; e < col; ++e)
{
cout << "Enter value: \n";
cin >> A[b][e];
}
}
cout << "Input Matrix B values: ";
for(int b1 = 0; b1 < row; ++b1)
{
for(int e1 = 0; e1 < col; ++e1)
{
cout << "Enter value: \n";
cin >> B[b1][e1];
}
}
}
if(select == 'a')
{
for (int c = 0; c < row; ++c)
{
for (int c1 = 0; c1 < col; ++c1)
{
C[c][c1] = A[c][c1] + B[c][c1];
}
}
for (int i = 0; i < row; i++)
{
for(int j = 0; j < col; j++)
{
cout << A[i][j] << " ";
}
for(int j = 0; j < col; j++)
{
cout << B[i][j] << " ";
}
for(int j = 0; j < col; j++)
{
cout << "\t";
cout << C[i][j] << " ";
}
cout << endl;
}
}
if(select == 's')
{
for (int c2 = 0; c2 < row; ++c2)
{
for (int c3 = 0; c3 < col; ++c3)
{
C[c2][c3] = A[c2][c3] - B[c2][c3];
}
}
for (int i = 0; i < row; i++)
{
for(int j = 0; j < col; j++)
{
cout << A[i][j] << " ";
}
for(int j = 0; j < col; j++)
{
cout << B[i][j] << " ";
}
for(int j = 0; j < col; j++)
{
cout << "\t";
cout << C[i][j] << " ";
}
cout << endl;
}
}
}
while (select != 'q');
return 0;
}
char menu(char operation)
{
cout << "Welcome to the Menu!";
cout << "\n? menu "
<< "\ni input"
<< "\na addition"
<< "\ns subtraction"
<< "\nm multiplication"
<< "\nt transpose"
<< "\nq quit program";
cout << "\n\nInput the symbol for your desired operation: ";
cin >> operation;
return operation;
}
Welcome!
Enter 2 numbers for the row and column of the matrices:
(Space in between) 2 2
Input Matrix A values: 1 2 3 4
Input Matrix B values: 1 2 3 4
Welcome to the Menu!
? menu
i input
a addition
s subtraction
m multiplication
t transpose
q quit program
Input the symbol for your desired operation: a
3 4 3 4 6 8
3 4 3 4 6 8
Welcome to the Menu!
? menu
i input
a addition
s subtraction
m multiplication
t transpose
q quit program
Input the symbol for your desired operation:
// When a enter 1 2 3 4 for both matrices, why do i only see 3 and 4, 3 and 4????