You need curly braces. And remember that else only attaches to the one nearest if, so the invalid operator message will print every time that the operand isn't %.