My code does what I want it to and then some?

Hey, normally I would see this as a good thing but in this case its not. When I run this code the first 8 lines it spits out is exactly what I want. Why is it spitting more stuff out and how do I stop it?

Thanks in Advance
I guess I should have attached the code

#include <iostream>
#include <ctime>
using namespace std;
int main()
{
srand((unsigned)time(0));
const int numRows=4, numCols=5;
const int cRow=4, cCol=5;
int cP[cRow][cCol];
int A[numRows][numCols]={0}, B[numRows][numCols]={0};
int C[numRows][numCols];

for (int i=0; i<numRows; i++)
{
for (int j=0; j<numCols; j++)
{
A[i][j]=rand() %25;
B[i][j]=rand() %25;
C[i][j]=A[i][j] + B[i][j];
cout << C[i][j] << "\t";
}
cout << endl;
}
for(int k=0; k,cRow; k++)
{
for(int l=0; l<cCol; l++)
{
int* ArrayPointer = &C[k][l];
cout << C[k][l] << "\t";
}
cout << endl;
}
system("pause");
return 0;
}
It would help to know what you want.

It looks like your code is just populating A and B with some random values, and storing the sum into C, and printing the contents of C twice for some reason...is that what you mean? You are printing C once inside the loop as you populate it (the i/j loop) and again afterward in the k/l loop.
The first time c is populated it is suppose to be populated with subscript and the second time it is suppose to be populated using pointers. Then a bunch more stuff comes up and I don't know where it is coming from or how to make it go away. While the code is compiling something pops up asking me to "break" or "continue".
You should reread the section on "populating an array using pointers" as what you are currently doing actually does nothing. It just assigns to a pointer you never use. I think you might be referring to using something like this equivalence:
1
2
array[subscript] = value;
*(array + subscript) = value;
Topic archived. No new replies allowed.