switch not working

I am making a traffic simulation for school, but I'm getting stuck with my switch. The traffic simulation is a state machine, which means I can switch states when for example I press the button for pedestrians the program will switch to another state.

However, I'm stuck with the switch. My variable for the STATE is constantly zero, even if I hard code it to be something else. It still keeps on returning to zero.

Here is the code for the switch :

void verkeer() {
  switch (STATE) {
    case RUST :
      if ( slagboomIsOmhoog() == false ) {
        if ( autoVanRechts() ) {
          RUST_on_Exit();
          STATE = AUTO_RECHTS;
          AUTO_RECHTS_on_Entry();
          break;
        } 
        if ( autoVanLinks() ) {
          RUST_on_Exit();
          STATE = AUTO_LINKS;
          AUTO_LINKS_on_Entry();
          break;
        } 
        if ( isNacht() ) {
          RUST_on_Exit();
          STATE = OVERGANG_NACHTSTAND;
          OVERGANG_NACHTSTAND_on_Entry();
          break;
        } 
        if ( voetgangerKnop() ) {
          RUST_on_Exit();
          STATE = VOETGANGER_WACHTEN;
          VOETGANGER_WACHTEN_on_Entry();
          break;
        }
      }
    case AUTO_RECHTS :
      if ( checkTimer() >= 5000 ) {
        AUTO_RECHTS_on_Exit();
        STATE = AUTO_RECHTS_ORANJE;
        AUTO_RECHTS_ORANJE_on_Entry();
        AUTO_RECHTS_ORANJE_do();
        break;
      }
    case AUTO_RECHTS_ORANJE :
      if ( checkTimer() >= 5000 ) {
        AUTO_RECHTS_ORANJE_on_Exit();
        STATE = AUTO_RECHTS_ROOD;
        AUTO_RECHTS_ROOD_on_Entry();
        AUTO_RECHTS_ROOD_do();
        break;
      }
    case AUTO_RECHTS_ROOD :
      if ( checkTimer() >= 1000 ) {
        STATE = RUST;
        RUST_on_Entry();
        RUST_do();
        break;
      }
    case AUTO_LINKS :
      if ( checkTimer() >= 5000 ) {
        AUTO_LINKS_on_Exit();
        STATE = AUTO_LINKS_ORANJE;
        AUTO_LINKS_ORANJE_on_Entry();
        AUTO_LINKS_ORANJE_do();
        break;
      }
    case AUTO_LINKS_ORANJE :
      if ( checkTimer() >= 5000 ) {
        AUTO_LINKS_ORANJE_on_Exit();
        STATE = AUTO_LINKS_ROOD;
        AUTO_LINKS_ROOD_on_Entry();
        AUTO_LINKS_ROOD_do();
        break;
      }
    case AUTO_LINKS_ROOD :
      if ( checkTimer() >= 1000 ) {
        STATE = RUST;
        RUST_on_Entry();
        RUST_do();
        break;
      }
    case VOETGANGER_WACHTEN :
      if ( slagboomIsOmhoog() ) {
        STATE = VOETGANGER_LOPEN;
        VOETGANGER_LOPEN_on_Entry();
        VOETGANGER_LOPEN_do();
        break;
      }
    case VOETGANGER_LOPEN :
      if ( checkTimer() >= 10000 ) {
        STATE = VOETGANGER_OVERGANG_NIET_LOPEN;
        VOETGANGER_OVERGANG_NIET_LOPEN_on_Entry();
        VOETGANGER_OVERGANG_NIET_LOPEN_do();
        break;
      }
    case VOETGANGER_OVERGANG_NIET_LOPEN :
      if ( checkTimer() >= 6000 ) {
        STATE = VOETGANGER_NIET_LOPEN;
        VOETGANGER_NIET_LOPEN_on_Entry();
        VOETGANGER_NIET_LOPEN_do();
        break;
      }
    case VOETGANGER_NIET_LOPEN :
      if ( slagboomIsOmhoog() == false ) {
        STATE = RUST;
        RUST_on_Entry();
        RUST_do();
        break;
      }
    case OVERGANG_NACHTSTAND :
      if ( slagboomIsOmhoog() ) {
        STATE = NACHTSTAND;
        NACHTSTAND_on_Entry();
        NACHTSTAND_do();
        break;
      }
    case NACHTSTAND :
      if ( isNacht() == false ) {
        NACHTSTAND_on_Exit();
        STATE = RUST;
        RUST_on_Entry();
        RUST_do();
        break;
      }
  }
}

And the code for the functions:

void RUST_on_Entry() {
  resetTimer();
}

void RUST_do() {
  stoplichtenRood();
  buzzerNietLopen();
  slagboomOmlaag();
  displayNietLopen();
}

void RUST_on_Exit() {
  stoplichtenUit();
}

void AUTO_RECHTS_on_Entry() {
  stoplichtAan(ROOD_LINKS);
  stoplichtAan(GROEN_RECHTS);
  startTimer();
}

void AUTO_RECHTS_on_Exit() {
  stoplichtUit(GROEN_RECHTS);
}

void AUTO_RECHTS_ORANJE_on_Entry() {
  stoplichtAan(ORANJE_RECHTS);
  resetTimer();
}

void AUTO_RECHTS_ORANJE_do() {
  startTimer();
}

void AUTO_RECHTS_ORANJE_on_Exit() {
  stoplichtUit(ORANJE_RECHTS);
}

void AUTO_RECHTS_ROOD_on_Entry() {
  stoplichtAan(ROOD_RECHTS);
  resetTimer();
}

void AUTO_RECHTS_ROOD_do() {
  startTimer();
}

void AUTO_LINKS_on_Entry() {
  stoplichtAan(ROOD_RECHTS);
  stoplichtAan(GROEN_LINKS);
  startTimer();
}

void AUTO_LINKS_on_Exit() {
  stoplichtUit(GROEN_LINKS);
}

void AUTO_LINKS_ORANJE_on_Entry() {
  stoplichtAan(ORANJE_LINKS);
  resetTimer();
}

void AUTO_LINKS_ORANJE_do() {
  startTimer();
}

void AUTO_LINKS_ORANJE_on_Exit() {
  stoplichtUit(ORANJE_LINKS);
}

void AUTO_LINKS_ROOD_on_Entry() {
  stoplichtAan(ROOD_LINKS);
  resetTimer();
}

void AUTO_LINKS_ROOD_do() {
  startTimer();
}

void VOETGANGER_WACHTEN_on_Entry() {
  slagboomOmhoog();
}

void VOETGANGER_LOPEN_on_Entry() {
  startTimer();
}

void VOETGANGER_LOPEN_do() {
  buzzerLopen();
  displayLopen();
}

void VOETGANGER_OVERGANG_NIET_LOPEN_on_Entry() {
  resetTimer();
}


void VOETGANGER_OVERGANG_NIET_LOPEN_do() {
  buzzerOvergang();
  displayOvergang();
}

void VOETGANGER_NIET_LOPEN_on_Entry() {
  slagboomOmlaag();
}

void VOETGANGER_NIET_LOPEN_do() {
  displayNietLopen();
}

void OVERGANG_NACHTSTAND_on_Entry() {
  slagboomOmhoog();
}

void NACHTSTAND_on_Entry() {
  buzzerUit();
}

void NACHTSTAND_do() {
  displayExtraGevaar();
  stoplichtenOranjeKnipperen();
}

void NACHTSTAND_on_Exit() {
  slagboomOmlaag();
}

And last, al the states.

const int RUST = 0;
const int AUTO_RECHTS = 1;
const int AUTO_RECHTS_ORANJE = 2;
const int AUTO_RECHTS_ROOD = 3;
const int AUTO_LINKS = 4;
const int AUTO_LINKS_ORANJE = 5;
const int AUTO_LINKS_ROOD = 6;
const int VOETGANGER_WACHTEN = 7;
const int VOETGANGER_LOPEN = 8;
const int VOETGANGER_OVERGANG_NIET_LOPEN = 9;
const int VOETGANGER_NIET_LOPEN = 10;
const int OVERGANG_NACHTSTAND = 11;
const int NACHTSTAND = 12;

int STATE;

Thanks in advance,

Thomas

I really have no intention of stitching your code back together. Post ALL of the code as one block of code, as the IDE sees it. If the whole code exceeds the 9500 character limit, use Reply (not the Quick Reply field) and the Additional Options link that looks nothing like a link, and attach your code.

Please post a complete program that shows the problem.

My variable for the STATE is constantly zero, even if I hard code it to be something else. It still keeps on returning to zero.

It sounds like you have more than one variable named STATE, probably one global and at least one other local.