There is still a minor problem that the program is sometimes halted when the procedure arrival is run, I still can't find out the reason. I have tested many times and most of them work, just sometimes it doesn't.
That is actually a though one as the error could depend on many variables. The biggest difficulty is that you use random values, so the chance of being able to repeat the exact same situation that generates the error is very slim.
As a first suggestion: Try to remove (comment out) the calls to randomize as that removing those will generate the same 'random' number sequence over and over again for each startup. Try and see if you are able to trigger the error. If you are able to then please show use exactly what you have given for input.
Other things to consider:
- try to see if it only happens with a odd or even number of flights entered
- check and see if it only happening when a certain number of gateways are already 'occupied'
Maybe someone else around has an idea. tbh i haven't looked at the rest of your code in depth yet as i'm a bit busy doing other things as well atm.
PS: in case you are sure the error is inside procedure arrival then log the value of every variable and print out something at every line so you can see what is happening exactly.