Cannot enter my code into a question without getting an error

Follow the pictures. This is driving me crazy and seems to make no sense at all.

before error

after error

So I can enter a few lines of code without a problem, but then the next line of code makes it improperly formatted??? The code is formatted properly, as can be seen from the pictures. Am I a total dummy and missing something or am I right to be totally pissed at this stupid bug?