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
1 2 1 2 2 4
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: s
1 2 1 2 0 0
3 4 3 4 0 0
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: m
1 2 1 2 7 10
3 4 3 4 15 22
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: t
1 2
3 4
1 3
2 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: i
Enter 2 numbers for the row and column of the matrices:
(Space in between) 3 3
Input Matrix A values: 1 2 3 4 5 6 7 8 9
Input Matrix B values: 1 2 3 4 5 6 7 8 9
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
1 2 4 1 2 4 2 4 8
4 5 7 4 5 7 8 10 14
7 8 9 7 8 9 14 16 18
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:
//How come when I enter new values for the 3 x 3 matrix, some of the values are incorrect?
int row, col;
cin >> row >> col;
float A[row][col]; // Error 1
cin >> row >> col; // Error 2
cout << "Input Matrix A values: ";
for(int b = 0; b < row; b++)
{
for(int e = 0; e < col; e++)
{
cin >> A[b][e];
}
}
Error 1: the C++ standard requires that the size of statically allocated array is known during compilation. You have to use dynamic allocation, or allocate "big enough" static array and check that user-given row,col do not exceed that.
Error 2: Changing these variables does not resize the array.