Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and the Yahoo Answers website is now in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

# How do i fix this matrices adding, subtracting, multiplying, c++ program?

heres the program

#include <stdio.h>

int main(void)

{

int a,b,c,i,j,k,c;

printf("Enter the values of Matrix A");

for(int i=0;i<3;i++)

{

for(int j=0;j<3;j++)

{

scanf("%d", a[i][j]);

}

}

printf("Enter the values of Matrix B");

for(int k=0;k<3;k++)

{

for(int l=0;l<3;l++)

{

scanf("%d", a[k][l]);

}

}

for(int m=0;m<3;m++)

{

for(int n=0;n<3;n++)

{

c[m][n] = 0;

}

}

printf("Addition: ");

for(i=0;i<3;i++)

{

for(j=0;j<3;j++)

{

c[i][j] = a[i][j] + b[i][j];

scanf("%d" , c[i][j]);

}

}

printf("Subtraction ");

for( i=0;i<3;i++)

{

for( j=0;j<3;j++)

{

C[i][j] = a[i][j] - b[i][j];

scanf("%d" , c[i][j]);

}

}

printf("Multiplication");

for( i=0;i<3;i++)

{

for( j=0;j<3;j++)

{

c[i][j] = 0;

for(int k=0;k<3;k++)

{

c[i][j] = c[i][j] + a[i][k]*b[k][j];

}

return 0;

}

heres the errors

c:\documents and settings\owner.shelbylaptop\my documents\visual studio 2008\projects\tes\tes\test.cpp(4) : error C2040: 'c' : 'int' differs in levels of indirection from 'int '

c:\documents and settings\owner.shelbylaptop\my documents\visual studio 2008\projects\tes\tes\test.cpp(43) : error C2065: 'C' : undeclared identifier

c:\documents and settings\owner.shelbylaptop\my documents\visual studio 2008\projects\tes\tes\test.cpp(61) : fatal error C1075: end of file found before the left brace '{' at 'c:\documents and settings\owner.shelbylaptop\my documents\visual studio 2008\projects\tes\tes\test.cpp(49)' was matched

### 3 Answers

Relevance
• Favorite Answer

In this line:

int a,b,c,i,j,k,c;

you have the variable "c" defined twice, once as an array, and once as an int. Get rid of the one declared as an int since you dont use it.

in this bit of code you use "C" instead of "c", change it to "c"

printf("Subtraction ");

for( i=0;i<3;i++)

{

for( j=0;j<3;j++)

{

C[i][j] = a[i][j] - b[i][j];

scanf("%d" , c[i][j]);

}

}

you also use scanf() when I think yuo want printf()

you dont have enough closing braces in this part

printf("Multiplication");

for( i=0;i<3;i++)

{

for( j=0;j<3;j++)

{

c[i][j] = 0;

for(int k=0;k<3;k++)

{

c[i][j] = c[i][j] + a[i][k]*b[k][j];

}

besides, it doesnt make much sense, so re check it

• your considerable function ought to take the enter on if that could be a decimal or integer interior an if assertion that works on if the int or decimal variable has a value. Then reckoning on what that fee is you ought to take the enter of the two numbers, back in an if assertion. After that, i'm undecided the type you want to deal with what operation this equipment is going to do.

• Add Try and catch statements in order to see where the problem lies. Ensure your error message is discriptive.

Just looking at the code, it looks like your array's are declared as integers but, what if the user does not put in an integer? Also, are these actually arrays?

Sorry but C++ isn't my language of choice. Good luck to you!

Still have questions? Get your answers by asking now.