optional matrix programm not working

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
#include <iostream>
using namespace std;

int matrixA[2][3];
	int matrixB[2][3];
	int matrixC[2][3];
	int i, j;

void add(){
	for( i=0;i<2;i++){
		for( j=0;j<3;j++){
			matrixC[i][j]=matrixA[i][j]+matrixB[i][j];
			}
	}
}
void sub(){
	for( i=0;i<2;i++){
		for( j=0;j<3;j++){
			matrixC[i][j]=matrixA[i][j]-matrixB[i][j];
			}
	}
}
void multi(){
	for( i=0;i<2;i++){
		for( j=0;j<3;j++){
			matrixC[i][j]=matrixA[i][j]*matrixB[i][j];
			}
	}
}
int div(){
	for( i=0;i<2;i++){
		for( j=0;j<3;j++){
			matrixC[i][j]=matrixA[i][j]/matrixB[i][j];
			}
	}
}

//void printMatrix(){
//}

int main(){
	int op;
	
	// GETING VALUSE FORM A AND B
	cout << "Enter matrix A :" << endl;
	for( i=0;i<2;i++){
		for( j=0;j<3;j++){
			cin >> matrixA[i][j];
			}
	}
	
	cout << "Enter matrix B :" << endl;
	for( i=0;i<2;i++){
		for( j=0;j<3;j++){
			cin >> matrixB[i][j];
			}
	}
	// CHOSING OPPERATION 1
	cout<<"----------------------------------------"<<endl;
	cout<<" Choose Operation to Compute Matrix C "<<endl;
	cout<<"----------------------------------------"<<endl;
	cout<<" Enter 1 to Add"<<endl;
	cout<<" Enter 2 to Subtract"<<endl;
	cout<<" Enter 3 to Multiply"<<endl;
	cout<<" Enter 4 to Divide"<<endl;
	cout<<"----------------------------------------"<<endl;
	cout<<"Enter Your Choice: ";
	cin>>op;

	// CHOSING OPPERATION 2
	switch(op){
		case 1: add();
		case 2: sub();
		case 3: multi();
		case 4: div();
	}
	
	// DISLAYING C
	cout << "Matrix C :" << endl;
	for( i=0;i<2;i++){
		for( j=0;j<3;j++){
			cout << matrixC[i][j] << " ";
			}
		cout << endl;
	}
	
	
	system("pause");
	} 
71
72
73
74
75
76
	switch(op){
		case 1: add();   break;
		case 2: sub();   break;
		case 3: multi(); break;
		case 4: div();   break;
	}

BTW, that's not how you multiply matrices, ... and there's really no such thing as matrix division.

Do you mean to multiply by a scalar value? In that case, you should only enter a single matrix and the value to multiply it. Likewise for 'division', which is multiplying by a scalar's reciprocal.

Also, watch your return types. (Set your compiler to complain when anything is wrong.)

Hope this helps.
Topic archived. No new replies allowed.