adding arrays.....

im gettig lots of errors and i have no clue why. can someone test it for me and tell me wassup


#include <conio>
#include <iostream>


int getvalues (int nRow, int number);
int add (int nRow ,int nCol);

void main ()
{



const int nNumRows1=3;
const int nNumCols1=3;
const int nNumRows2=3;
const int nNumCols2=3;


int matval;
int nCol1;
int nRow1;
int nRow2;
int nCol2;
int nCol;
int nRow;




int firstMatrix[nNumRows1][nNumCols1]={0};
int secondMatrix[nNumRows2][nNumRows2]={0};
int sumMatrix[nNumRows2][nNumCols2]={0};

// Create 1st matrix! chuh!

for (int nRow = 0; nRow < nNumRows1; nRow++)
{





for (int nCol = 0; nCol < nNumCols1; nCol++)

{

getvalues (nRow,nCol);
cin>>matval;

int firstmatrix[nRow][nCol] = matval;


}



}

// create second matrix! chuh!
cout<<" Now enter the values for the second matrix"<<endl;



for (int nRow1 = 0; nRow1 < nNumRows2; nRow1++)
{





for (int nCol1 = 0; nCol1 < nNumCols2; nCol1++)

{

getvalues (nRow1,nCol1);
cin>>matval;

int secondmatrix[nRow1][nCol1] = matval;


}



}



add(nRow2,nCol2);




//showing it back to dem bumbo

for (int nRow2 = 0; nRow2 < nNumRows1; nRow2++)

{
for (int nCol2 = 0; nCol2 < nNumCols1; nCol2++)

{
cout<<sumMatrix[nRow][nCol]<<"\t";
}

}

getch();

}



int getvalues (int nRow, int nCol)
{


cout<< "Enter value for row "<<nRow+1<<" column "<<nCol+1<<endl;
//cin>>matval;
//nMatrix[nRow][nCol] = matval;
}




int add (int nRow ,int nCol)
{
const int nNumRows1=3;
const int nNumCols1=3;
const int nNumRows2=3;
const int nNumCols2=3;


int matval;
int nCol1;
int nRow1;
int nRow2;
int nCol2;




for (int nRow2 = 0; nRow2 < nNumRows2; nRow2++)
{

for (int nCol2 = 0; nCol2 < nNumCols2; nCol2++)

{

int sumMatrix[nRow2][nCol2]= ( firstMatrix[nRow2][nCol2])+ ( secondMatrix[nRow2][nCol2]);

}



}

}

















Could you please go back and edit your code to:
- not have loads of extra blank line
- use appropriate indenting
- and tags!

Then you will prob get higher quality help.

Thanks!

Andy

"How to use tags"
http://www.cplusplus.com/articles/z13hAqkS/
See if this helps

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

int getvalues (int nRow, int number);
int add (int nRow ,int nCol);

void main ()
{



const int nNumRows1=3;
const int nNumCols1=3;
const int nNumRows2=3;
const int nNumCols2=3;


int matval = 0 ;
int nCol1  = 0 ;
int nRow1  = 0 ;
int nRow2  = 0 ;
int nCol2  = 0 ;
int nCol   = 0 ;
int nRow   = 0 ;




int firstMatrix[nNumRows1][nNumCols1]={0};
int secondMatrix[nNumRows2][nNumRows2]={0};
int sumMatrix[nNumRows2][nNumCols2]={0};

// Create 1st matrix! chuh!

for (int nRow = 0; nRow < nNumRows1; nRow++)
{
		for (int nCol = 0; nCol < nNumCols1; nCol++)
		{

				getvalues (nRow,nCol);
				cin>>matval;
				firstmatrix[nRow][nCol] = matval;
		}
}

// create second matrix! chuh!
cout<<" Now enter the values for the second matrix"<<endl;



for (int nRow1 = 0; nRow1 < nNumRows2; nRow1++)
{
		for (int nCol1 = 0; nCol1 < nNumCols2; nCol1++)
		{

				getvalues (nRow1,nCol1);
				cin>>matval;
				secondmatrix[nRow1][nCol1] = matval;
		}
}



add(nRow2,nCol2);

//showing it back to dem bumbo

	for (int nRow2 = 0; nRow2 < nNumRows1; nRow2++)

	{
		for (int nCol2 = 0; nCol2 < nNumCols1; nCol2++)
		{
			cout<<sumMatrix[nRow][nCol]<<"\t";
		}

	}

getch();

}



int getvalues (int nRow, int nCol)
{


	cout<< "Enter value for row "<<nRow+1<<" column "<<nCol+1<<endl;
//cin>>matval;
//nMatrix[nRow][nCol] = matval;
}




int add (int nRow ,int nCol)
{
		const int nNumRows1=3;
		const int nNumCols1=3;
		const int nNumRows2=3;
		const int nNumCols2=3;


		int matval = 0;
		int nCol1  = 0;
		int nRow1  = 0;
		int nRow2  = 0;
		int nCol2  = 0;




		for (int nRow2 = 0; nRow2 < nNumRows2; nRow2++)
		{

				for (int nCol2 = 0; nCol2 < nNumCols2; nCol2++)

				{

					int sumMatrix[nRow2][nCol2]= ( firstMatrix[nRow2][nCol2])+ ( secondMatrix[nRow2][nCol2]);

				}



		}

}
On lines 49 and 53 you have inconsistencies with your variable names. You went from firstMatrix (capital M) to firstmatrix (lowercase m) and then did the same with secondMatrix.

On line 79, what is getch() and what is it supposed to do?

In your two functions you have variables that haven't been named inside of them. For instance, on line 121, you use the variables firstMatrix and secondMatrix. But those haven't been declared within, or passed to, your add() function.

Finally, I think you'll have to declare sumMatrix outside of the for loop in order to use it.

Try to get all that sorted out and see if you still have problems. Focus on one function at a time, and try to get it so that all of the variables that you need to use will be available. Taking everything one step at a time should help out a little.

EDIT:

getch() isn't giving an error after I fixed one problem.

#include <conio> should read #include <conio.h>
Last edited on
Topic archived. No new replies allowed.