cygwin script problem windows

I'm using cygwin to make some scripts,but I have the following problem.
If I create a simple script like this one:

if [ $# -ne 2 ]
echo "Error"
exit 1
fi
echo "`expr $1 + $2`"

I obtain line 6: syntax error:unexpected end of file.

If I create the same script with cat>filename.txt and execute it with ./filename.txt it works.
I can't use only cat because if I want to make a huge script I don't want to start from scratch eveytime.

You're missing a 'then'.

if [ $# -ne 2 ]
then
        echo "Error"
        exit 1
fi

echo "`expr $1 + $2`"

Yes you are right,but it doesn't work anyway.
Maybe I should save in linux format?

I painfully remember this thread:

http://www.unix.com/unix-dummies-questions-answers/120449-how-use-shell-script-specific-commands.html\#post302358129

(3rd, 8th and 9th posts)

I donwloaded notepad and save the .txt file in unix format instead of pc format and now it works.