Code only works correctly the first time?

Doesn't compile for me.