note: it is in reverse order, i– this is important due to the nature of the algorithm
for(int i=u;i>=0;i–) //changed it to i=u, u is the counter for the outer loop this increases efficiancy
{
ahits[i+1]+=ahits_(attackvalue/6); //attackvalue is 3 for a tank
ahits_=(attackvalue/6); //if it misses
}
for 2 tanks
for tanks attackvalue=3 so (attackvalue/6) is always .5
when i enter a tank, and i=0 (u=0) then
ahits[1]+=ahits[0].5
which is:
ahits[1]+=.5 (ahits[1]=.5)
then
ahits[0]=.5 (ahits[0]=.5)
ahits={.5,.5};
for the second tank, i=1;
ahits[2]+=ahits[1].5
which is:
ahits[2]+=.5.5=.25 (ahits[2]=.5)
then
ahits[1]=.5 (ahits_=.25)
now ahits={.5,.25,.25} but we have to do when i=0 also
ahits[1]+=ahits[0].5
which is:
ahits[1]+=.5*.5
ahits[1]=ahits[1]+.25 (ahits[1]=.5)
then
ahits[0]=.5
ahits[0]=.5.5=.25 (ahits[0]=.25)
so after 2 tanks ahits={.25,.5,.25} 25% miss, 50% 1 hit, 25% 2 hits
i might code this up for a special purope, in the meantime, you could try to get it to work. I’ll work on the 2d array so i can get say 25% attack hits once, defence hits twice, or whatever, then to do multiple rounds…___