Need help with menu code

I have a project where i have a arduino and a rotary encoder with a button and i'm coding a menu system. I have the 2 of the three menus, i cant get the code to go to the 3 menu.

the flow of my program is kind of 2D array where certain spots at the end of the row navigate up and down to other rows.

main loop is these functions

encoder();
that reads the dial and moves the menu across the row

menushow();
takes the dial number and displays the menu option

debounce is on a interrupt and calls menuaction()
that has a list of actions to do depending on where in the "array" you are in

the code to get to the effectmenu is here, which is the part doesnt work, yet other navigating code works

if(whichmenu == 1 && menuspot == 7 )
{
whichmenu=3;
}

how the menu array looks for reference

menu 1 (dimensions): 1, 2, 3, 4, 5, 6, 7, 8, 9
menu 2 (sounds) : 1, 2, 3, 4, 5, 6, 7, 8, 9
menu 3 (effects) : 1, 2, 3, 4, 5, 6, 7, 8, 9

where whichmenu variable is the rows
and menuspot is the columns

Here is the code, I deleted some of the functions/codes that dont have anything to do to make it easier to navigate.

#include <Encoder.h>
#define ENCODER_OPTIMIZE_INTERRUPTS
Encoder myEnc(0, 5);
long oldPosition  = 0;
long newPosition = 0;

#include <Wire.h>
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"
Adafruit_7segment myDisplay = Adafruit_7segment();

const int buttonPin = 1;
int buttonState = 0; 

int ledState = HIGH;      
int lastButtonState = LOW; 

int menuspot=1;
int lastposition;
int whichmenu=1; //1 dimension 2 sounds 3 effects

int portalledpin=6;
// shift register stuff //do not touch
int SER_Pin = 10;   //pin 14 on the 75HC595
int RCLK_Pin = 11;  //pin 12 on the 75HC595
int SRCLK_Pin = 12; //pin 11 on the 75HC595
#define number_of_74hc595s 1 
#define numOfRegisterPins number_of_74hc595s * 8
boolean registers[numOfRegisterPins]; 

void setup() 
{
  myDisplay.begin(0x70);
  pinMode(portalledpin, OUTPUT); 
  pinMode(buttonPin, INPUT_PULLUP); 

  pinMode(9, INPUT); // battery pin
  
  pinMode(SER_Pin, OUTPUT);
  pinMode(RCLK_Pin, OUTPUT);
  pinMode(SRCLK_Pin, OUTPUT);
  
  allregisterHIGH();
  writeRegisters();
  attachInterrupt(0, debounce, FALLING);
  digitalWrite(6, HIGH);
}

void loop() 
{
encoder(); 
menushow();
allregisterHIGH();
writeRegisters();
}

void encoder()
{
  newPosition = myEnc.read()/4;
  if(newPosition>oldPosition)
  {
    menuspot++;
    allregisterHIGH();
    writeRegisters();
  }
  if(newPosition<oldPosition)
  {
    menuspot--;
    allregisterHIGH();
    writeRegisters();  
  }
  
  if(whichmenu==1 && menuspot>7){menuspot=1;}//dimension menu
  if(whichmenu==1 && menuspot<1){menuspot=7;}//dimension menu
  
  if(whichmenu==2 && menuspot>9){menuspot=1;}//sound menu
  if(whichmenu==2 && menuspot<1){menuspot=9;}//sound menu
  
  if(whichmenu==3 && menuspot>7){menuspot=1;}//effect menu
  if(whichmenu==3 && menuspot<1){menuspot=7;}//effect menu
  oldPosition=newPosition;
}

void menushow()
{
  switch(whichmenu)
    {
      case 1: dimensionmenu();
        break;
      case 2: soundsmenu();
        break;
      case 3: effectsmenu();
        break;
      default:myDisplay.print(6666, DEC);
              myDisplay.writeDisplay();
        break;
    }
}



void menuaction()
{
//--------------- Dimension menu -------------------------//  
  if(whichmenu == 1 && (menuspot==1 || menuspot==2 || menuspot==3 || menuspot==4 || menuspot==5 ))
    {
      digitalWrite(portalledpin, HIGH);  
    }    
  if(whichmenu==1 && menuspot==6)
    {
      whichmenu=2;  
    }
  if(whichmenu == 1 && menuspot == 7 )
    {
      whichmenu=3;
    }
//-------------------- Sound Menu ----------------------------//  
  if(whichmenu == 2 && menuspot == 1)
    {
      //action  
    }
  else if(whichmenu == 2 && menuspot == 2)
    {
      //action  
    }
   else if(whichmenu == 2 && menuspot == 3)
    {
      //action  
    }
   else if(whichmenu == 2 && menuspot == 4)
    {
      //action  
    }
       else if(whichmenu == 2 && menuspot == 5)
    {
      //action  
    }
           else if(whichmenu == 2 && menuspot == 6)
    {
      //action  
    }
           else if(whichmenu == 2 && menuspot == 7)
    {
      //action   
    }
           else if(whichmenu == 2 && menuspot == 8)
    {
      //action  
    }
    else if(whichmenu == 2 && menuspot == 9)
    {
      whichmenu=1;
    }
    else
    {
      // default action
    }   
//-------------------- Sound Menu ----------------------------//  
      if(whichmenu==3 && menuspot==7)
    {
      whichmenu=1;  
    }
}

separate page for the debounce function

long lastDebounceTime = 0; 
long debounceDelay = 50;

void debounce() {
  int reading = digitalRead(buttonPin);
  if (reading != lastButtonState) {
    // reset the debouncing timer
    lastDebounceTime = millis();
  } 
  if ((millis() - lastDebounceTime) > debounceDelay) {
    buttonState = reading;
    
    buttonState = digitalRead(buttonPin);
//------------------------------------------------- 
    if (buttonState == LOW) 
    {  
       menuaction();
    } 
    else 
    {
    }
//-------------------------------------------------
}
  lastButtonState = reading;
}

menu display codes

void dimensionmenu()
{
  switch(menuspot)
    {
      case 1: //menu page 1
      break;
      case 2: //menu page 2
      break; 
      case 3: //menu page 3
      break; 
      case 4: //menu page 4
      break;
      case 5: //menu page 5
      break;
      case 6: //go to sound menu
      break;
      case 7: //go to effects menu
      break;
      
      default: //default menu page
      break;
  }  
}

void soundsmenu()
{
  switch(menuspot)
    {
      case 1:  //menu page 1
      break;
      case 2:  //menu page 2
      break; 
      case 3: //menu page 3
      break; 
      case 4: //menu page 4
      break;
      case 5://menu page 5
      break;
      case 6: //menu page 6
      break;
      case 7: //menu page 7
      break;
      case 8: //menu page 8
      break;
      case 9: go to back to previous menu
      
      break;
      
      default: //default menu page 

      break;
  }  
}

void effectsmenu()
{
  switch(menuspot)
    {
      case 1: //menu page 1
      break;
      case 2: //menu page 2
      break; 
      case 3: //menu page 3
      break; 
      case 4: //menu page 4
      break;
      case 5: //menu page 5
      break;
      case 6: //menu page 6
      break;
      case 7: // got to previous menu
      break;
      default: // default manu
      break;
  }
  
}

Thank you in advance for anyone that can help. I apologize if i posted this in the wrong area or if i posted it in the wrong area. Feel free to ask me any questions.

PS i also included the original code no edits as attachments

debounce.ino (1.47 KB)

debug.ino (816 Bytes)

FEATHER_Teensy_Encoder_Basic_and_seven_segment_V5.ino (6.08 KB)

menus.ino (2.49 KB)

shift_out.ino (961 Bytes)

words.ino (648 Bytes)

Thanks for the reply. I'm going to look and test this out. I need to learn about class and virtual. I would also need to recode my project into this code which will take time. I was hoping someone could tell me why my code wasn't working, i'm thinking its a conceptual error with one or more lines of code. But Thank you i will use this to learn and implement this into my project when i redo it and in my next project.