What have you used to edit your code? If you use a
word processor, you are liable to insert control characters which the compiler cannot parse. That might explain the illegal characters.
You haven't declared any of your variables in the code you posted. You have to declare every variable not later than the first occasion you use it.