First, edit your post to include [ code ] tags around your code. The forum software eats some of your code if you don't.
Second, you never declared what kind of input you are using. It will default to a floating input. Do you have an external pullup or pulldown resistor?
Which Arduino are you using?