dont know where it goes wrong

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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
idk where this goes wrong,please help me point my errors
i keep getting message

//

<#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<cstring>

void MatrixA(long nZeileA,long nSpalteA);
void MatrixB(long nZeileB,long nSpalteB);
void Transpose(long nZeileB,long nSpalteB,long i,long j,long b[5][5],long transpose [5][5]);
void MatrixA1(long nZeileA,long nSpalteA,long i,long j,long a[5][5]);
void MatrixB1(long nZeileB,long nSpalteB,long i,long j,long b[5][5]);
void MatrixAB(long nZeileB,long nSpalteA,long i,long j,long k,long nZeileA,long nSpalteB,long a[5][5],long b[5][5],long c[5][5],long sum,long mult[5][5]);
// the words MatrixAB is underlined
int main()
{
	char chAuswahl;
	long a[5][5],b[5][5],c[5][5],d[5][5],mult[5][5],transpose[5][5];
	long i=0,j=0,k=0,nZeileA=0,nZeileB=0,nSpalteA=0,nSpalteB=0,o=0,p=0,sum=0;

	printf("A => Matrix A eingeben\n");
	printf("B => Matrix B eingeben\n");
	printf("M => Berechne AB und Ausgabe\n");
	printf("T => Transporniere B und Ausgabe\n");
	printf("==============================\n");
	printf("E => Ende\n\n");
	fflush(stdin);
	printf("Auswahl: ");
	scanf("%c",&chAuswahl);

	switch(chAuswahl)
	{
		case 'A':
		case 'a':
			{	
				system("CLS");
				MatrixA1(nZeileA,nSpalteA,i,j,a);
				main();
				break;
			}
			
		case 'B':
		case 'b':
			{	
				system("CLS");
				MatrixB1(nZeileB,nSpalteB,i,j,b);
				main();
				break;
			}
			
		case 'M':
		case 'm':
			{	MatrixAB(nZeileB,nSpalteA,i,j, k,nZeileA,nSpalteB,sum, a,b,c,mult);//'sum',and 'b' are underlined
				break;
			}

		case 'T':
		case 't':
			{
				Transpose(nZeileB,nSpalteB,i,j,b,transpose);
				break;
			}

		case 'E':
		case 'e':
			{	
				exit(1);
			}
			
		default:
			{
				system("CLS");
				main();
				break;
			}
	}

	fflush(stdin);			
	_getch();
}


void MatrixA(long nZeileA,long nSpalteA)
{	printf("Zeile Matrix A: ");
	scanf("%d",&nZeileA);
	printf("Spalte Matrix A: ");
	scanf("%d",&nSpalteA);
}
void MatrixA1(long nZeileA,long nSpalteA,long i,long j,long a[5][5])
{
	MatrixA(nZeileA,nSpalteA);
	if(nZeileA >5 || nSpalteA>5)
	{printf("Fehler!Maximal 5x5!");}
	if (nZeileA<=0 ||nSpalteA<=0)
	{main();}
	
	else 
		for (i=0;i<nZeileA;i++)
		{
				for (j=0;j<nSpalteA;j++)
				{
					printf("Element A%d,%d : ",i,j);
					scanf("%hd",&a[i][j]);
				}
		}
		printf("%d%d",&a[i][j]);
		for (i=0;i<nZeileA;i++)
			{
				printf("\n");
				for (j=0;j<nSpalteA;j++)
				{printf("%d\t",&a[i][j]);}
		}
	system("PAUSE");
	system("CLS");

}
void MatrixB(long nZeileB,long nSpalteB)
{	printf("Zeile Matrix B: ");
	scanf("%d",&nZeileB);
	printf("Spalte Matrix B: ");
	scanf("%d",&nSpalteB);
}
void MatrixB1(long nZeileB,long nSpalteB,long i,long j,long b[5][5])
{
	MatrixB(nZeileB,nSpalteB);
	if(nZeileB >5 || nSpalteB>5)
	{printf("Fehler!Maximal 5x5!");}
	if (nZeileB<=0 ||nSpalteB<=0)
	{main();}
	
	else 
		{for (i=0;i<nZeileB;i++)
			{
				for (j=0;j<nSpalteB;j++)
				{
					printf("Element B%d,%d : ",i,j);
					scanf("%hd",&b[i][j]);
				}
			}
	for (i=0;i<nZeileB;i++)
			{
				printf("\n");
				for (j=0;j<nSpalteB;j++)
				{printf("%d\t",&b[i][j]);}
		}
	system("PAUSE");
	system("CLS");
	}

}
void MatrixAB(long nZeileB,long nSpalteA,long i,long j,long k,long nZeileA,long nSpalteB,long a[5][5],long b[5][5],long c[5][5],long sum=0,long mult[5][5]) 
// the words MatrixAB is underlined
{
	MatrixA(nZeileA,nSpalteA);
	MatrixB( nZeileB,nSpalteB);
	if (nZeileB !=nSpalteA)
	{printf("Multiplikation nicht moeglich!");
	system("PAUSE");
	system("CLS");
	}
	else
	{
		for (i=0;i<nZeileA;i++)
		{
				for (j=0;j<nSpalteB;j++)
				{
						for (k=0;k<nZeileB;k++)
						{sum=sum+ a[i][k]*b[k][j];}
					mult[i][j]= sum;
					sum=0;
				}
		}
		for(i=0;i<nZeileA;i++)
	{
		for(j=0;j<nSpalteB;j++)
		
			printf("%d\t ",mult[i][j]);
			printf("\n\n");
	}
	}
	
		
}
void Transpose(long nZeileB,long nSpalteB,long i,long j,long b[5][5],long transpose[5][5])
{
	MatrixB1(nZeileB,nSpalteB,i,j,b);
	for (i=0;i<nZeileB;i++)
	{
		for(j=0;j<nSpalteB;j++)
		{
			transpose[j][i]=b[i][j];
		}
	}
	printf("Transpose B");
	for (i=0;i<nSpalteB;i++)
	{
		for(i=0;i<nZeileB;i++)
		{
			printf("%d\t",transpose[i][j]);
		}
		printf("\n");
	}>
Last edited on
Hi,

Please use code tags - edit your post, select all the code, press the <> button on the format menu. Your code should look like this:


1
2
void MatrixAB(long nZeileB,long nSpalteA,long i,long j,long k,long nZeileA,long nSpalteB,long a[5][5],long b[5][5],long c[5][5],long sum,long mult[5][5]);
// the words MatrixAB is underlined 


1
2
3
4
5
case 'M':
case 'm':
{ MatrixAB(nZeileB,nSpalteA,i,j, k,nZeileA,nSpalteB,sum, a,b,c,mult);//'sum',and 'b' are underlined
break;
}


Do you have your arguments in the right order ?

If you have compiler errors, then post them here in full - we can explain them to you :+)

Some other things:

Never, ever call main() from within your program, investigate how to use loops instead. Search on this site for bool controlled while loop . The C _Bool is a little different to the C++ bool

http://stackoverflow.com/questions/1608318/is-bool-a-native-c-type


When calling scanf, make use of it's return value to see if it worked.

Hope all is going well at your end :+)
hi thanks,there you go..
1
2
3
4
5
1>c:\users\yser\documents\visual studio 2010\projects\binu1400-testat3\binu1400-testat3.cpp(53): error C2664: 'MatrixAB' : cannot convert parameter 8 from 'long' to 'long [][5]'
1>          Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\yser\documents\visual studio 2010\projects\binu1400-testat3\binu1400-testat3.cpp(153): error C2548: 'MatrixAB' : missing default parameter for parameter 12
1>c:\users\yser\documents\visual studio 2010\projects\binu1400-testat3\binu1400-testat3.cpp(203): fatal error C1075: end of file found before the left brace '{' at 'c:\users\yser\documents\visual studio 2010\projects\binu1400-testat3\binu1400-testat3.cpp(185)' was matched
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


these are the errors.so it still ok when i enter the value for matrix a and b but when it didt go well when i want to multiply or transpose the matrices
Hi,

The errors point to differences in type: do you have your arguments in the right order? The function declaration and definition must match.
its not in the right order,actually,i dont really know how to
Ok,

So you have 3 things: The declaration of the function on line 16; The definition of the function on line 154; The calling of the function on line 56.

These 3 things must have the parameters / arguments in the same order.
ok got it!
i already change it into the same order but the error still there

error C2548: 'MatrixAB' : missing default parameter for parameter 11 error:default argument not at the end of parameter list
Last edited on
Ok,

long sum=0

Try putting the default parameter at the end of the list in the declaration, and in the definition, then change the order in the function call to reflect that.

When writing your code from the start, put in the function declaration, then copy & paste it to the function definition, that way they will be the same. It seems that default parameters must be at the end as well.

When using your IDE, it should tell you what arguments are available in a function call.

Some other things which are good style, but not causing problems at the moment:

Declare, initialise and comment your variables one per line, rather than 20 of them in one line of code.


this is my latest code
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/*binu1400
testat3



*/

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>

void MatrixA(long nZeileA,long nSpalteA);
void MatrixB(long nZeileB,long nSpalteB);
void Transpose(long nZeileB,long nSpalteB,long i,long j,long b[5][5],long transpose [5][5]);
void MatrixA1(long nZeileA,long nSpalteA,long i,long j,long a[5][5]);
void MatrixB1(long nZeileB,long nSpalteB,long i,long j,long b[5][5]);
void MatrixAB(long MultiplikatinAB[5][5],long nZeileA,long nSpalteA,long nZeileB,long nSpalteB,
	long i,long j,long k,long a[5][5],long b[5][5],long sum=0);
// the words MatrixAB is underlined
int main()
{
	char chAuswahl;
	long a[5][5],b[5][5],c[5][5],d[5][5],MultiplikationAB[5][5],transpose[5][5];
	long i=0,j=0,k=0,nZeileA=0,nZeileB=0,nSpalteA=0,nSpalteB=0,sum=0;

	printf("A => Matrix A eingeben\n");
	printf("B => Matrix B eingeben\n");
	printf("M => Berechne AB und Ausgabe\n");
	printf("T => Transporniere B und Ausgabe\n");
	printf("==============================\n");
	printf("E => Ende\n\n");
	fflush(stdin);
	printf("Auswahl: ");
	scanf("%c",&chAuswahl);

	switch(chAuswahl)
	{
		case 'A':
		case 'a':
			{	
				system("CLS");
				MatrixA1(nZeileA,nSpalteA,i,j,a);
				main();
				break;
			}
			
		case 'B':
		case 'b':
			{	
				system("CLS");
				MatrixB1(nZeileB,nSpalteB,i,j,b);
				main();
				break;
			}
			
		case 'M':
		case 'm':
			{	MatrixAB(MultiplikationAB,nZeileA,nSpalteA,nZeileB,nSpalteB,i,j,k,a,b,sum=0);//'sum',and 'b' are underlined
				main();
				break;
			}

		case 'T':
		case 't':
			{
				Transpose(nZeileB,nSpalteB,i,j,b,transpose);
				main();
				break;
			}

		case 'E':
		case 'e':
			{	
				exit(1);
			}
			
		default:
			{
				system("CLS");
				main();
				break;
			}
	}

	fflush(stdin);			
	getchar();
}


void MatrixA(long nZeileA,long nSpalteA)
{	printf("Zeile Matrix A: ");
	scanf("%hd",&nZeileA);
	printf("Spalte Matrix A: ");
	scanf("%hd",&nSpalteA);
}
void MatrixA1(long nZeileA,long nSpalteA,long i,long j,long a[5][5])
{
	MatrixA(nZeileA,nSpalteA);
	if(nZeileA >5 || nSpalteA>5)
	{printf("Fehler!Maximal 5x5!");}
	if (nZeileA<=0 ||nSpalteA<=0)
	{main();}
	
	else 
		for (i=0;i<nZeileA;i++)
		{
				for (j=0;j<nSpalteA;j++)
				{
					printf("Element A%d,%d : ",i+1,j+1);
					scanf("%hd",&a[i][j]);
				}
		}
		printf("%d%d",&a[i][j]);
		for (i=0;i<nZeileA;i++)
			{
				printf("\n");
				for (j=0;j<nSpalteA;j++)
				{printf("%d\t",&a[i][j]);}
		}
	system("CLS");

}
void MatrixB(long nZeileB,long nSpalteB)
{	printf("Zeile Matrix B: ");
	scanf("%hd",&nZeileB);
	printf("Spalte Matrix B: ");
	scanf("%hd",&nSpalteB);
}
void MatrixB1(long nZeileB,long nSpalteB,long i,long j,long b[5][5])
{
	MatrixB(nZeileB,nSpalteB);
	if(nZeileB >5 || nSpalteB>5)
	{printf("Fehler!Maximal 5x5!");}
	if (nZeileB<=0 ||nSpalteB<=0)
	{main();}
	
	else 
		{for (i=0;i<nZeileB;i++)
			{
				for (j=0;j<nSpalteB;j++)
				{
					printf("Element B%d,%d : ",i,j);
					scanf("%hd",&b[i][j]);
				}
			}
	for (i=0;i<nZeileB;i++)
			{
				printf("\n");
				for (j=0;j<nSpalteB;j++)
				{printf("%d\t",&b[i][j]);}
		}
	system("PAUSE");
	system("CLS");
	}

}
void MatrixAB(long MultiplikationAB[5][5],long nZeileA,long nSpalteA,long nZeileB,long nSpalteB,
	long i,long j,long k,long a[5][5],long b[5][5],long sum=0) 
// the words MatrixAB is underlined
{
	MatrixA(nZeileA,nSpalteA);
	MatrixB( nZeileB,nSpalteB);
	if (nSpalteA==0 || nZeileB==0)
	{printf("Matrizen erst deefinieren!\n");}
	else if (nZeileB !=nSpalteA)
	{printf("Multiplikation nicht moeglich!");
	system("PAUSE");
	system("CLS");
	}
	else if(nSpalteA==nZeileB)
	{for(i=0;i<nZeileA;i++)
		{
		for(j=0;j<nSpalteB;j++)
		
		{MultiplikationAB[i][j]=0;}
		
		}
	
		for (i=0;i<nZeileA;i++)
		{
				for (j=0;j<nSpalteB;j++)
				{
						for (k=0;k<nZeileB;k++)
						
						{MultiplikationAB[i][j]+= a[i][k]*b[k][j];}
				}
		}
		for(i=0;i<nZeileA;i++)
	{
		printf("%*s ",nSpalteA*4," ");
		
		for(j=0;j<nSpalteB;j++)
		
		{printf("%4d ",b[i][j]);}	
		printf("\n\n");
	}
	
		for(i=0;i<2+nZeileA*4+nSpalteB*4;i++)
			{printf("-");}
		printf("\n");

		for(i=0;i<nSpalteA;i++)
		{
			for(j=0;j<nSpalteB;j++)
			{printf("%4d",a[i][j]);}

			printf(" |");

			for(k=0;k<nSpalteB;k++)
			{
				j=k;
				printf("%4d",MultiplikationAB[i][j]);
			}
			printf("\n");
		}
		printf("\n");
	}
	system("PAUSE");
	system("CLS");
	
		
}
void Transpose(long nZeileB,long nSpalteB,long i,long j,
	long b[5][5],long transpose[5][5])
{
	if(nZeileB==0)
	{
		printf("Matrizen erst definieren!: \n");}
	
	else
	{
		printf("Matrix B transpornieren\n");

	for (i=0;i<nZeileB;i++)
	{
		for(j=0;j<nSpalteB;j++)
		{
			transpose[j][i]=b[i][j];
		}
	}

	for (i=0;i<nSpalteB;i++)
	{
		printf("\n");
		for(j=0;j<nZeileB;j++)
		{
			printf("%3d",transpose[i][j]);
		}
	}
	}
	printf("\n");
	system("PAUSE");
	system("CLS");
}


it still does not go well for switch (case 'm' and 't)',meaning when i insert m or t,it does not go into the function,it stay there at main()
Hi,

As I mentioned earlier, do not call main(), as you do in your switch cases and in some of your functions.

Just wondering what error level you have your compiler set to - my compiler would throw a leg out bed if I called main() :+D With Visual Studio, is it -W4 which is one above the default level? Not the verbose one which prints out almost useless information about problems it sees in header files.

I notice that your functions are return type void, but none of your function parameters are pointers, so none of the variables in main will be set to any value. Functions use local copies of arguments, unless the argument is a pointer, in which case it will change that variables value in terms of the scope of the calling function (in this case main)

Also, you should check the return value from scanf to see if it worked or not. If it didn't work then you have a garbage value for those variables.

Have you considered learning to use a debugger? You can step through your code 1 line at a time and keep an eye on the value of your variables.

Also, i would prefer not to use i and j as variables, they can cause problems because they look very similar. I like to use a small word instead - in this case Row and Col or whatever the Germanic equivalent is. I am guessing the language is Deutsch ?
Topic archived. No new replies allowed.