Problem with an on off switch

hi,
I am looking for some advice on this program I am having a problem with.
The simulation is for a food blender. Ie one start switch to switch the system on and off. The switch should allow any of the three different speed selector switches, slow, medium and fast to operate only if the on/off switch is on and not to work if the on/off switch is off.

The on/off switch is input 2. The three speeds are inputs 3,4 and 5
The answer seems obvious, but for some reason it's puzzling me.

Many thanks
Derek

/*
course assignment - household appliance
*/
int MOTOR = 9; // the pin for the MOTOR

void setup()
{
pinMode(MOTOR,OUTPUT); // tell Arduino MOTOR is an output
pinMode(2, INPUT);
pinMode(3, INPUT);
pinMode(4, INPUT);
pinMode(5, INPUT);
}

void loop()

{
if (digitalRead (3)== HIGH) // if switch is pressed then jump to next line and switch on motor
{
analogWrite(MOTOR, 50); // Sets the PWM mark:space ratio speed LOW.
while(!digitalRead(3)== HIGH)
{
delay(10); // do nothing, just delay a very tiny amount
}
}

else if (digitalRead (4)== HIGH) // if switch is pressed then jump to next line and switch on motor
{
analogWrite(MOTOR, 127); // Sets the PWM mark:space ratio speed MEDIUM.
while(!digitalRead(4)== HIGH)
{
delay(10); // do nothing, just delay a very tiny amount
}
}

else if (digitalRead (5)== HIGH) // if switch is pressed then jump to next line and switch on motor
{
analogWrite(MOTOR, 255); // Sets the PWM mark:space ratio speed HIGH.
while(!digitalRead(5)== HIGH)
{
delay(10); // do nothing, just delay a very tiny amount
}
}

else
{
digitalWrite(MOTOR, LOW);
}
}

Welcome to the Forum. Please read the two posts at the top of this Forum by Nick Gammon on guidelines for posting here, especially the use of code tags ("</>") when posting source code files. Also, before posting the code, use Ctrl-T in the IDE to reformat the code in a standard format, which makes it easier for us to read.

If the buttons give a HIGH value when pressed,
(which I doubt, but your code made that assumption)

the following could work:

/*
course assignment - household appliance - cheat from arduino forum
*/
int MOTOR = 9;

void setup()
{
    pinMode(MOTOR,OUTPUT);                    // tell Arduino MOTOR is an output
}

//speedTable[8] = { 0, 255, 127, 127, 50, 50, 50, 50 };       // low speed wins
speedTable[8] = { 0, 255, 127, 255, 50, 255, 127, 255 };     // high speed wins

void loop() {
byte speed = 0;

    if (digitalRead(2)) {                        // if Power is on
    byte keyState = 0;                        // make an index from buttons
        keyState |= (digitalRead(3)?4:0);       // slow
        keyState |= (digitalRead(4)?2:0);       // medium
        keyState |= (digitalRead(5)?1:0);       // fast
        speed = speedTable[keyState];     // get configured speed
    }
    analogWrite(MOTOR, speed);
    delay(20);                           // 50 times per second
}