array addition formula

Hi There,

I am using the following statements in a loop. The last statement is supposed to add them together but all three lines yield the same values. What seems to be the problem here. These are the statements:

1
2
3
fxsum [xx1][contactpnt1] = xforce [xx1][contactpnt1];
x [xx1] = fxsum [xx1][contactpnt1];
resultfx [xx1] += x[xx1];


Any help is appreciated.
What this code does is resultfx [xx1] += xforce [xx1][contactpnt1]; (and of course also set fxsum and x). What it is supposed to do I'm not sure..
Were you trying to add all xforce[xx1][0 to something] ?
Yes. I am trying to add all the values of xforce [xx1][contactpnt1] into resultfx [xx1] but it's not working for some reason.
Last edited on
I have other similar statements with different variables and the same problem persists.
If I understand correctly,
1
2
result[xx1] = 0;
for(int i = 0; i < something; i++) result[xx1] += xforce[xx1][i];

Is what it should be.
Yes correct but all 3 statements are giving me the same result. Whereas the 3rd statement is supposed to give the summation of the previous one.
Summation to what? Maybe resultfx[xx1] is 0 ?
Also, post more code, because these 3 lines don't really say anything..
When I print all 3 statements I get the same result; all 3 are equal, so the summation (3rd statment) is not working for some reason. I can't figure out why. None of them is 0, though.
Last edited on
I wrote:
post more code, because these 3 lines don't really say anything..
It's working now. Thank you hamsterman.
Topic archived. No new replies allowed.