Magic 8-ball sketch

I'm trying to create a "Magic 8-ball" sketch. The LCD should show "Your question please", then once the switch is pressed, it should choose a random number from 0-9 and output the appropriate response. My "if" statement is not working, as soon as the Arduino starts, it shows one of the responses, waits 5 seconds, then shows another response and loops endlessly. The switch on pin 7 has no effect. What am I missing?

void setup()
{
pinMode(7, INPUT); //declare switch as input
digitalWrite(7, HIGH); //connects internal resistor to input, connecting pin 7 to ground will show a high on pin 7
pinMode(backLight, OUTPUT); //declare backlight pin as output
lcd.begin(20,4); //columns, rows
lcd.clear(); //start with blank screen
lcd.setCursor(0,0); //set cursor to column 0, row 0

}

void loop()
{
analogWrite(backLight, 85); //turn backlight on
lcd.print("Your question please");

//int val = digitalRead(inputPin); //read input value

if (digitalRead(7) == HIGH)
{
lcd.begin(20,4); //columns, rows
lcd.clear(); //start with blank screen
lcd.setCursor(0,0); //set cursor to column 0, row 0
randomNumber = random(0, 9);
switch (randomNumber) {
case 0:
lcd.print("Highly unlikely");
delay(5000);
break;
case 1:
lcd.print("Yes");
delay(5000);
break;
case 2:
lcd.print("No");
delay(5000);
break;
case 3:
lcd.print("Could you repeat thequestion?"); //no space to make output look good
delay(5000);
break;
case 4:
lcd.print("Go ask your mother");
delay(5000);
break;
case 5:
lcd.print("Results are cloudy");
delay(5000);
break;
case 6:
lcd.print("It is almost certain");
delay(5000);
break;
case 7:
lcd.print("Conditions are");
lcd.setCursor(0,1);
lcd.print("almost perfect");
delay(5000);
break;
case 8:
lcd.print("No, no, no, a");
lcd.setCursor(0,1);
lcd.print("thousand times, no!");
delay(5000);
break;
case 9:
lcd.print("I'm checking...");
delay(5000);
}

}
else
{delay(1000);};
}

You are using the internal pull-ups, so the default state of your input is high. Try checking the digitalread against LOW instead.

Read your comment for the digitalWrite() statement in setup(). It is wrong. When the internal pullup resistor is enabled, pressed is LOW and released is HIGH (like the top of the switch).

    randomNumber = random(0, 9);

will actually return random numbers between 0 and 8.

All cases should have a break statement, even the last one. What happens if you add a case?

Thanks guys. I had copied the switch part of the sketch from an online how-to. You can't believe everything you read online!

Still learning the basics.

For what it's worth, you could probably dump the switch statement entirely. Make an array of possible responses, then just use lcd.print( responses[ randomNumber ] ).

I think you'd end up using more memory, but the code would be a lot cleaner and it looks like you've got the overhead to spare.