Matrix Operations - Help !

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include <iostream>
#include <cstdlib>
#include <iomanip>
using namespace 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????
closed account (10X9216C)
1
2
int row, col;
float A[row][col], B[row][col], C[row][col];


You don't initialize row and col before creating your arrays.
I don't understand?
never mind, i found the problem. Thanks so much ! : ))
Topic archived. No new replies allowed.