Expected Unqualified ID Error... The simple one

im running into one of those issues.. the simple ones..

Error:

C:\Users\Me\Desktop\Lantern\Lantern.ino:464:5: error: expected unqualified-id before 'else'
   } else if (Code == prevCode) {
     ^~~~
C:\Users\Me\Desktop\Lantern\Lantern.ino:469:5: error: expected unqualified-id before 'else'
   } else {
     ^~~~
C:\Users\Me\Desktop\Lantern\Lantern.ino:473:1: error: expected declaration before '}' token
 }
 ^

exit status 1

Compilation error: expected unqualified-id before 'else'

Code:

void Light_Controller(){

  if (Code != prevCode) {

     int Code = results.value;
     switch(Code) {
     
   /*
    * Red
    * Green
    * Blue
    * Yellow
    * Pale Yellow
    * Purple
    * Pink
    * Orange
    * White
    */
     case 0xFFA25D: 
       Serial.println("Code 1"); 
       off();
       flicker(1, 10, 2);
       break;

     case 0xFFE21D: 
       Serial.println("Code 2");
     
....

     case 0xFFFFFFFF: 
       Serial.println("QUIT ******* WITH MY CODE!");
       break;  

   /*
    * Red
    * Green
    * Blue
    * Yellow
    * Pale Yellow
    * Purple
    * Pink
    * Orange
    * White
    */
     default: 
       Serial.println("***         !! ERROR !!         ***");
       Serial.println("*** !! UNKNOWN CODE RECEIVED !! ***");
       Serial.println("***         !! ERROR !!         ***");
       Serial.println();
       Serial.println("Please Report \"ERR: 001\" to 573-***-**** OR Email ************@outlook.com");
     }
     delay(500);


    }

  } else if (Code == prevCode) {
    Serial.println("**********");
    Serial.println("* Repeat *");
    Serial.println("**********");

  } else {
    Serial.println("Now Ya Done ****** Yourself!");
  }

}

Snippets of code and/or error messages are rarely helpful. You need to post your entire sketch and the entire error message.

If your sketch is very large, create a smaller version that still demonstrates the error. In the process of doing this, you can often find your own errors. If not, post the small demonstration sketch

else if (Code == prevCode)

This and code below it is not in a function. You seem to have ended the Light_Controller() function too early

Auto Formatting the code in the IDE shows it up

    delay(500);
  }
}
else if (Code == prevCode)
{

the ellipsis is just there in place of a big section of (almost) exactly the same cases. those cases are not the culprit of the error because otherwise i would have gotten the error pointing to one of the end brackets in the case section.

AND BOB SAVES THE DAY AGAIN!!

Thank you!

(i knew it was something stupid simple lol)

It was not difficult to find.
As I said

This is particularly true when each { and } is placed on its own line. I cannot understand why people don't use it as a matter of course

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.