expected unqualified-id before 'if'

hi i am trying out a project and i am getting an error i have had a look on google ect and i can not find what i have done wrong can you spot it ? thank you for looking the i have marked the bit with the error

// project 5 -controlling traffic
// define all pins thar the buttons and lights are on
#define westButton 3
#define eastButton 13
#define westRed 2
#define westYellow 1
#define westGreen 0
#define eastRed 12
#define eastYellow 11
#define eastGreen 10

#define yellowBlinkTime 500//0.5 seconds for yell ow light blink
boolean trafficWest = true;  //west = true, est = false
int flowTime = 10000; //amount of time to let traffic flow
int changeDelay = 2000;// amount of time between color chsnges
void setup ()
{// set digital I/O pins
pinMode (westButton, INPUT);
pinMode (eastButton, INPUT);
pinMode (westRed, OUTPUT);
pinMode (westYellow, OUTPUT); 
pinMode (westGreen, OUTPUT);
pinMode (eastRed, OUTPUT);
pinMode (eastYellow, OUTPUT);
pinMode (eastGreen, OUTPUT);
 // set initial state for Lights west side is green first
 digitalWrite(westRed, LOW);
 digitalWrite(westYellow, LOW);
 digitalWrite(westGreen, HIGH);
 digitalWrite(eastRed, HIGH);
 digitalWrite(eastYellow, LOW);
 digitalWrite(eastGreen, LOW);
}
 void loop ()
 {
   if (digitalRead (westButton) == HIGH)// request west >est traffic flow
   if (trafficWest != true)// only cotinue traffic flowing in the opposite (east ) direction
   { trafficWest = true;//change traffic flow flag to west >east
   delay (flowTime); // give time for tarric to flow
   digitalWrite (eastGreen, LOW); // change east-facing lights from green
   //to yellow to red
   digitalWrite(eastYellow,HIGH);
   delay (changeDelay);
digitalWrite (eastYellow, LOW);
digitalWrite (eastRed, HIGH);
delay (changeDelay);
for ( int a =0; a < 5; a++)
//blink yellow light
{
  digitalWrite(westYellow, LOW);
  delay (yellowBlinkTime);
  digitalWrite (westYellow,HIGH);
  delay (yellowBlinkTime);
}
digitalWrite(westYellow, LOW);
digitalWrite(westRed, LOW);// chang west-facing Lights from red to green
digitalWrite (westGreen,HIGH);
   }
 }
 if(digitalRead (eastButton) == HIGH ) // request east>west traffic flow <<<<<<<<<<THIS IS THE BIT WITH THE ERROR
 {
   if (trafficWest == true)// only continue if traffic is .wesr
   
   
  
   //give time for traffic to flowin the opposit (west )direction
   {
     trafficWest =false;// change traffic flow flag to easr
      delay (flowTime);//give time for traffic to flow
      digitalWrite(westGreen, LOW);//change west light from green to yellow to red
      digitalWrite(westYellow, HIGH);
      delay (changeDelay);
      digitalWrite(westYellow, LOW);
      digitalWrite(westRed, HIGH);
      delay (changeDelay);
      for ( int a = 0;a <5 ;++)
      // blink yellow light
      {
        digitalWrite(eastYellow, LOW);
        delay (yellowBlinkTime);
        digitalWrite(eastYellow, HIGH);
         delay (yellowBlinkTime);
         digitalWrite(eastYellow, LOW);
         digitalWrite(eastRed, LOW);
         digitalWrite(eastGreen,HIGH);
      }
   }
 }

Post the error !!!

Mark

 if(digitalRead (eastButton) == HIGH ) // request east>west traffic flow <<<<<<<<<<THIS IS THE BIT WITH THE ERROR

Use ctrl-t (auto format) on your code and you will see that this statement and all subsequent lines are outside of loop(). The compiler is expecting a function there. Your curly brackets are not in the right places.

ok tried ctrl t ( thank you for that ) but it is saying no changes necessary for Auto format!! were should they go please

you will see that this statement and all subsequent lines are outside of loop().

Maybe put them inside "loop ()" ?

If you put the cursor to the left of a curly (or parenthesis) The matching curly (or parent) will be highlighted. Put the cursor to the left of the curly before the offending if statement and you will see the curly right after loop() highlighted. Auto format looks for unmatched curlies and parents. Yours match, just in the wrong place.

groundfungus:
Your curly brackets are not in the right places.

And after you fix that look carefully at your "for" loops. You've got a typo.

Hope this helps,

Brad
KF7FER

thank you all XD