Unqualified-d before else

I have an unqualified-id before else, and I don't know how to solve it.

int buttonPin = 2;  // set variables for component pins
int redLED = 4;
int buttonPress;  // declare variable for the button state
char answer;

void setup() {
  pinMode(buttonPin, INPUT);
  pinMode(redLED, OUTPUT);
}

void loop() {
  buttonPress = digitalRead(buttonPin);  // set variable to button pin reading
  if (buttonPress == HIGH) {             // if button is pressed, turn LED on
    answer = shouldItlight();
      if (answer == 'Y') {
        digitalWrite(redLED, HIGH);
      } else if (answer == 'N') {
        digitalWrite(redLED, LOW);  // otherwise, LED is off
      }
    }
  }
else if(buttonPress == LOW) {
    digitalWrite(redLED, LOW);
  }
  char shouldItlight() {
    char yesorno;
    Serial.println(" press y to light the button.");
    while (!Serial.available()) {}
    yesorno = Serial.read();

    return yesorno;  //returns a character
  }

Count the number of brackets. Add 1 when you see a {, and remove 1 when you see a }. The count should be 0 where it is expected to be 0.

If you indent your code correctly, you will immediately see the problem.

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