I have this code:
int sum = 0; for(int i = 0; i < POPULATION_SIZE; i++){ // loop through the population (0-99) for(int j = 0; j < 16; j++){ // loop through the individuals (in this case the cities) sum = COST[j][j+1]; } fitness[i] = sum; } I am trying to add all the COSTS. Sum is meant to equal the the total of adding all the elements.
The problem I'm facing is that each time the loop runs, sum is set to the next value, as aposed to the total of adding the previous and the current values.
Given people's answers I can now see my rather foolish error. Is this a case of remembered fundamentals before you over complicate?
+=and not=. b) It would be helpful for your future questions (one that aren't caused by simple typos like this one) to post how you get your data (in this caseCOSTandPOPULATION_SIZE)