Hi, I have written a small piece of code that runs through a loop of 100 array elements. It compares a variable (conttot) to each of these elements and tests to see if it is larger. If the variable is larger it shifts the other elements down the array by 1 place to make room for the new element. The new element is then inserted in the correct place (above the smaller values in the array)
I have been trying to debug this for a while, but with no success.
The output i am getting is the biggest value in the first slot, and the second largest element duplicated all the way down to the 100th.
can anybody see where the problem may be?
thx in advance
bob
Code://tests each element starting with biggest. for(a=0;a<=100;a++) { if(conttot>=colourArr[a]) { //shift all the other elements down to make room for the newest.. for(d=100;d>a;d--) { colourArr[d]=colourArr[d]; purecolours[d][0]=purecolours[d-1][0]; purecolours[d][1]=purecolours[d-1][1]; purecolours[d][2]=purecolours[d-1][2]; } //place the new element in its correct slot colourArr[a]=conttot; purecolours[a][0]=red; purecolours[a][1]=green; purecolours[a][2]=blue; break; } }