Here is a simple way to do what you want to achieve:
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
|
#include <iostream>
using std::cout;
int main()
{
int array[6][7], columntotal[6] = {0}, rowtotal[7] = {0}; //I think descriptive names are good.
int x, y, z = 1; //x & y are just used to iterate around loops, z will be used to fill up the array with some numbers.
for(x = 0; x < 6; ++x) //Just fill up the array with some numbers.
{
for(y = 0; y < 7; ++y)
{
array[x][y] = z;
++z;
}
}
for(x = 0; x < 6; ++x) //Sum the columns.
{
for(y = 0; y < 7; ++y)
{
columntotal[x] = columntotal[x] + array[x][y];
}
}
for(x = 0; x < 6; ++x) //Output the value of each column.
{
cout << columntotal[x] << "\n";
}
return 0;
}
|
That will sum columns. I'll leave it to you to figure out how to sum the rows. Btw, you are not using any functions from <cmath> so no need to include that header file.
As for the problems in your original code:
1 2 3 4
|
sum1+=array[x];
sum2+=array[y];
|
When accessing the elements in a 2d array, you must always refer to both dimensions to get the information.
Would be valid for example.
1 2
|
strcpy (array1,sum1);
strcpy (array2,sum2);
|
The way you are using strcpy here is incorrect. Also, strcopy requires inclusion of <cstring>. Hmm anyway I suggest reading about what strcopy does:
http://www.cplusplus.com/reference/cstring/strcpy/
And not using it in this program, because you don't need to.
You should also avoid using:
Try perhaps to use getchar() or something and try not to use system("anything").