Comparing elements in 2-dimens. array

Hello everybody,

I'm trying to improve my C++ skills on my own,
So I need a little bit help,
Hope you can help,here's my question:

I need to write a programm which can compare two elements in a two-dimensional array which is the following one:

int arr[4][2] = { {1,100},
{2,400},
{3,200},
{1,300} };

I have to add up the elents which have the same value of the
which have the same number in the first column;

for example: 1 -> 400 (100+300) / 2 -> 400 / 3 -> 200

But I have some problems in my code,here is what I could do so far:

for(int i=0;i<4;++i){
for(int j=0;j<2;++j){
if(arr[i][j]==arr[i+1][j]){ //elem. in same coulmn but diff. row
value = arr[i][j] + arr[i+1][j]; //values are added up
}
}

cout << " Value " << summe;
}

I would be thankful for every tip ;)
Last edited on
Topic archived. No new replies allowed.