need some help keeping LEDs on

i am trying to get it to turn the LED on when i press the button and have it remain on until i press the off button.
it works just fine with pin 9, it turns on and remains on until i press the off button. but when i press any other buttons the LED only stays on while i am holding the button and turns off when i release it.

what am i missing here
any and all suggestions and help is welcome, im new to this...

void setup() {
// put your setup code here, to run once:
pinMode(9,INPUT);
pinMode(10,INPUT);
pinMode(11,INPUT);
pinMode(12,INPUT);
pinMode(14,OUTPUT);
pinMode(15,OUTPUT);
pinMode(16,OUTPUT);
pinMode(17,OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
if (digitalRead(9)==HIGH)
digitalWrite(14,HIGH);

if(digitalRead(10)==HIGH)
digitalWrite(15,HIGH);

if(digitalRead(11)==HIGH)
digitalWrite(16,HIGH);

{if(digitalRead(12)==HIGH)
digitalWrite(14,LOW);
digitalWrite(15,LOW);
digitalWrite(16,LOW);
}}

    if (digitalRead(12) == HIGH)
      digitalWrite(14, LOW);
    digitalWrite(15, LOW);
    digitalWrite(16, LOW);

Which lines of code will be executed if pin 12 is HIGH ?
Which lines will be executed whatever the state of pin 12 ?
Are the line of code being executed the ones that you want ?

Note the code tags used when I pasted the code and also the code formatting when I used Tools/Auto Format in the IDE

if pin 12 is high then
digitalWrite(14, LOW);
digitalWrite(15, LOW);
digitalWrite(16, LOW);
will be executed

that function works fine from, its the turning them on that is the issue

Perhaps viewing that with a little better formatting will help.

void setup()
{
    // put your setup code here, to run once:
    pinMode(9,  INPUT);
    pinMode(10, INPUT);
    pinMode(11, INPUT);
    pinMode(12, INPUT);
    pinMode(14, OUTPUT);
    pinMode(15, OUTPUT);
    pinMode(16, OUTPUT);
    pinMode(17, OUTPUT);
}

void loop()
{
    // put your main code here, to run repeatedly:
    if ( digitalRead(9) == HIGH )
    {
        digitalWrite(14, HIGH);
    }

    if ( digitalRead(10) == HIGH )
    {
        digitalWrite(15, HIGH);
    }

    if ( digitalRead(11) == HIGH )
    {
        digitalWrite(16, HIGH);
    }

    {
        if ( digitalRead(12) == HIGH )
        {
            digitalWrite(14, LOW);
        }

        digitalWrite(15, LOW);
        digitalWrite(16, LOW);
    }
}

if pin 12 is high then
digitalWrite(14, LOW);
digitalWrite(15, LOW);
digitalWrite(16, LOW);
will be executed

Wrong

    digitalWrite(15, LOW);
    digitalWrite(16, LOW);

Will be executed regardless of the state of pin 12

ahh!

i see what you are saying.

how do i need to rewrite it then?

Put the statements to be executed when the condition is true in a pair of braces

Codieq742:
how do i need to rewrite it then?

Change this:

{if(digitalRead(12)==HIGH)
  digitalWrite(14,LOW);
  digitalWrite(15,LOW);
  digitalWrite(16,LOW);
}

To this:

if(digitalRead(12)==HIGH)
{
  digitalWrite(14,LOW);
  digitalWrite(15,LOW);
  digitalWrite(16,LOW);
}

IT WORKED!!
thank you.

why is it that it worked with

if (digitalRead(9)==HIGH)
digitalWrite(14,HIGH);

but not the others?

Without the braces only the next statement is executed. The braces denote a group of statements to be executed together.

The next thing to do is to write the sketch properly. You want the LEDs to change state when a switch BECOMES pressed, not IS pressed.

Look at the state change detection example.