In this case max=24 and strips are: 14, 23, 20.
I need all of them to reach 24 and print out how many extra strips did we need to reach that number. I'am probably messing up the for loop and its not repeating itself enough times, could someone help me out here? Oh yeah and there is lots of 0's aswell, but I can ignore them so hence ( !=0 )
1 2 3 4 5 6 7 8 9 10
for (int i=0; i<n; i++){
for (int j=i-1; j<n; j++){
if (strips[j].amount!=0){
if (strips[j].amount<max){
strips[j].amount++;
strips{j].extra++;
}
}
}
}
For one thing, you're making an out of bounds reference on the first iteration.
Line 1: First iteration i=0
Line 2: First iteration j=-1
Lines 3-6: strips[-1] is an out of bounds reference