For k = 2 to NoOfMissiles
if Distance(k) < Distance(k-1) then Closest = k
next k
I could be wrong, but this code snippet looks like it would set Closest to k whenever an element in the array is less than the one before it. If that's true, then it wouldn't return the closest in an array like [6 3 9 8]. It would see 3<6 so Closest would be 3, but then it would see 8<9, so it would set Closest to 8, forgetting about 3.
Here's what I'd do to find the closest:
Closest=1
Closestdist=Distance(1)
For k = 2 to NoOfMissiles
if Distance(k) < Closestdist
Closest = k
Closestdist=Distance(k)
endif
next k
If this piece of code went through the example array [6 3 9 8], it would first set closest to 1 and closestdist to 6 (before the loop). Then it would see 3<6, so it would set closest to 2 and closestdist to 3. The last two checks would be 9<3 and 8<3, both of which are false, leaving closest at 2.