Code seems to be correct, but why does it sometimes go wrong?

Printable View