expected '}' before 'else'

Hello. I have this issue where it says "expected '}' before 'else'" and there are no issues relating to if, else if, or else. this is a piece of the code. the code is pretty big so I don't include much of it.

expected '}' before 'else'

Can Somebody tell me the issue with this? I can give more code if required.

Thanks!

a bit of code:

[codevoid loop() {
} //  -------------------- NOW YOU SEE IT

bool getTime(const char *str)
{
  int Hour, Min, Sec;
]

a bit of code that would cause the condition you see

[codevoid loop() {
// -------------------- NOW YOU DON'T

bool getTime(const char *str)
{
int Hour, Min, Sec;
][/code]

look at the code in brackets above the if and determine where you left out the closing bracket ].

if you highlight a bracket it shows you its mate

You probably have a ; after the ‘)’ on the ‘if’ line.

if(something == thatThing); <———<<<< if this ; is there, remove it.

But really, you need to show us your sketch.


Use CTRL T to format your code.
Attach your ‘complete’ sketch between code tags, use the </> icon in the posting menu.

[code]Paste your sketch here[/code]

No sorry it does not have the issue, as it doesnt have a ; misplaced. However, here is some extra code:

else if (mast_pressed == '2')
      {
        mast_pressed = 0;
        lcd.clear();
        Serial.println("New Admin code Requesteed");
        lcd.print("Are you sure?");
        lcd.setCursor(0, 2);
        lcd.print("A for Yes");
        lcd.setCursor(0, 3);
        lcd.print("B for No");
        lcd.setCursor(0, 1);
        mast_pressed = keypad_key.getKey();
        if (mast_pressed == 'A');
        {
          lcd.clear();
          lcd.print("Enter PIN:");
          lcd.setCursor(0, 2);
          do
          {
            mast_pressed = keypad_key.getKey();

            if (mast_pressed > 47 && mast_pressed < 58)
            {
              mastpass[mastdigit++] = mast_pressed;
              lcd.print(mast_pressed);
            }
          }
          while (mastdigit != 4);
          EEPROM.write(mastdigit, 2);
          lcd.clear();
          lcd.print("Done!");
          Serial.println("New Password set: ");
          Serial.print(mast_pressed);
          mast_pressed = 0;
          delay(1500);
          lcd.clear();
          adminmenu();
        }
        else if (mast_pressed == 'B')
        {
          adminmenu();
        }
      }

Please post the entire sketch. Can't tell from this fragment.

Likely, somewhere in your code you put an 'else' inside a block before the '}' closing bracket. It is not a valid C syntax.

Also the compiler will tell you which line number the error occurs in. Look at the first error, copy and paste the error messages here.

It is a Really big sketch, so i will attach it via file.

otherlcdcode.ino (13.4 KB)

davidgao1345:
No sorry it does not have the issue, as it doesnt have a ; misplaced.

Ahem...

        if (mast_pressed == 'A');

My bad. I should've known!

“ My bad. I should've known!”

Yes.

Next time don’t be lazy.