Trouble returning boolean value from called function using switch statement

This is my first time posting in the Arduino forum. I am building a simple controller with an 20x4 lcd display and 4x4 matrix keypad input. I declared a global variable called bool eject that is initially set to false. when the “C” key is pressed it displays two options. One is to press the “#” key to toggle the value to true, the other is to press the “" key which sets the value to false and both inputs return the display to the main screen.
I attempted to do so by calling a function with a switch statement. In the case"#": the variable is set to true, and case"
”: the variable is set/remains false.

When I run the code the display is correct and an input of either “#” or “*” returns the display to the main screen, but the eject value has not changed.

I am relatively new to Arduino programming so there are many things that I do not yet know or understand. Any guidance is greatly appreciated.

#include <Keypad.h>
#include <Wire.h> 
#include <PCF8574.h>
#include <LiquidCrystal_I2C.h>

#define lcdi2caddress 0x27

PCF8574 pcf_01(0x22);
PCF8574 pcf_02(0x21);

bool eject = false;
bool runmode = false;

long total = 25;  
volatile long done = 0; 
long current1 = total; 
long current2 = done;
const byte interrupt = 2;  


const byte rows = 4;
const byte cols = 4;

char keys[rows][cols]
  {
    {'1','2','3','A'},
    {'4','5','6','B'},
    {'7','8','9','C'},
    {'*','0','#','D'}
  };

byte rowPins[rows]={4,5,6,7};
byte colPins[cols]={8,9,10,11};

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, rows, cols);

LiquidCrystal_I2C lcd(lcdi2caddress,20,4); 

void setup()
  {    
    pcf_02.begin();
    pcf_01.begin();
    pcf_01.write8(LOW);
    
    lcd.init(); //initialize the lcd
    lcd.backlight(); //open the backlight
  
    pinMode(interrupt, INPUT);
    attachInterrupt(1, count, FALLING); 
     
    
    lcd.setCursor(0,0);
    delay(1000);
    lcd.print("*****          *****");
    lcd.setCursor(0,1);
    lcd.print("***              ***");
    lcd.setCursor(0,2);
    lcd.print("**               ***");
    lcd.setCursor(0,3);
    lcd.print("********************");
    delay(1000);
    lcd.setCursor(7,0);
    lcd.print("      ");
    delay(750);
    lcd.setCursor(5,1);
    lcd.print("          ");
    delay(750);
    lcd.setCursor(4,2);
    lcd.print("           ");
    delay(3000);
    lcd.clear();
    lcd.setCursor(2,0);
    lcd.print("Counter");
    lcd.setCursor(0,2);
    lcd.print("TOTAL:");
    lcd.setCursor(0,3);
    lcd.print("DONE:");
    lcd.setCursor(7,2);
    lcd.print(total);
    lcd.setCursor(7,3);
    lcd.print(done);
  }

void loop() 
  {
 
    if(current2 != done)  //Updates the current2 volatile long integer used for the counter ISR
      {
        mainScreen();
        current2 = done;
      }

    if(current1 != total)  //Updates the current1 volatile long integer used for the counter ISR
      {
        mainScreen();
        current1 = total;
      }

    if(done < 0)  //Prevents the long integer done from holding a value less than 0
      {
        done = 0;
      }

    if(total < 1)  //Prevents the total stack size from holding a value less than 1
      {
        total = 1;
      }
  
    if(done >= total) //Resets done items to 0 
      {
        done = 0;
      }
    char key = keypad.getKey(); 

    if(key == 'A')
      {
        runmode = false;
        
        lcd.clear();
        lcd.setCursor(2,0);
        lcd.print("Enter Total");
        lcd.setCursor(2,1);
        lcd.print("Then Press #");
        lcd.setCursor(2,2);
        lcd.print("Press * To Clear");
        total = GetNumber();
        mainScreen();
      }
    if(key == 'B')
      {
        runmode = false;
        
        lcd.clear();
        lcd.setCursor(2,0);
        lcd.print("Enter Parts Done");
        lcd.setCursor(2,1);
        lcd.print("Then Press #");
        lcd.setCursor(2,2);
        lcd.print("Press * To Clear");
        done = GetNumber();
        mainScreen();
      }
    if(key == 'C')
      {
        runmode = false;
        lcd.clear();
        lcd.setCursor(2,0);
        lcd.print("Ejection Sequence");
        lcd.setCursor(2,1);
        lcd.print("# To Eject");
        lcd.setCursor(2,3);
        lcd.print("* To Cancel");

        eject = manualeject();

      }
    if(key == 'D')
    {
      runmode = !runmode;
      mainScreen();
      
    }
    if(key == '2')
      {
        done++;
        mainScreen();
      }
    if(key == '8')
      {
        done--;
        mainScreen();
      }
    if(key == '4')
      {
        total--;
        mainScreen();
      }
    if(key == '6')
      {
        total++;
        mainScreen();
      }

  }

void mainScreen()
  {
    lcd.clear();
    lcd.setCursor(2,0);
    lcd.print("Stacker/Counter");
    lcd.setCursor(0,2);
    lcd.print("TOTAL:");
    lcd.setCursor(0,3);
    lcd.print("DONE:");
    lcd.setCursor(7,2);
    lcd.print(total);
    lcd.setCursor(7,3);
    lcd.print(done);

    if(eject == true)
    {
      lcd.setCursor(15,2);
      lcd.print("eject");
    }
    else
    {
      lcd.setCursor(15,2);
      lcd.print("     ");
    }
    if(runmode == true)
    {
      lcd.setCursor(15,3);
      lcd.print("Auto");
    }
    else
    {
      lcd.setCursor(15,3);
      lcd.print("     ");
    }
  }

long GetNumber()
  {
    lcd.setCursor(15,3);
    long num = 0;
    char key = keypad.getKey();
    while(key != '#')
    {
      switch (key)
        {
          case NO_KEY:
          break;

          case '0': case '1': case '2': case '3': case '4':
          case '5': case '6': case '7': case '8': case '9':
          lcd.print(key);
          num = num * 10 + (key - '0');
          break;

          case '*':
          num = 0;
          lcd.setCursor(15,3);
          lcd.print("      ");
          lcd.setCursor(15,3);
          break;

          break;
        }

      key = keypad.getKey();
    }

    return num;
  }


void count()
  {
     static unsigned long last_millis = 0;
     unsigned long m = millis();
     
     if (m - last_millis < 100)     
       {
        
       }
       
     else
       {
        done++;
       }
       
     last_millis = m;
  }

 bool manualeject()
   {
      bool ejectOK = false;
      
      char key = keypad.getKey();
        
      while(key != '#' && key != '*')
       {
        switch(key)
         {
           case NO_KEY:
           break;
               
           case'1': case'2': case'3': case'A':
           case'4': case'5': case'6': case'B':
           case'7': case'8': case'9':  case'C': 
           case'0': case'D':
           break;
          
           case'#':
             ejectOK = true;
           break;
  
           case'*':
             ejectOK = false;
           break;
            
         }
         key = keypad.getKey();
      }
      mainScreen();
      return ejectOK;
    }

Change

bool manualeject()

to

void manualeject()

and do not try to return ejectOK.

ejectOK is global so when you change it in the function, it is changed globally.

Use code tags to post your code

You code is hard to read. Hit "ctrl-t" in the IDE to auto-format it. Then re-post it using CODE TAGS.

while(key != '#' && key != '*')

Your switch statement will only be run if key != '#' and '*'

Learn to use code tags!! Did you read the sticky post at the top of the topic?

In this function the return of the boolean value is no problem. The bigger problem is that the while loop is completely wrong here. If the pressed key is not '*' or '#' the while loop will never end, if it is one of these two characters, it will not enter the while loop and the function always returns false.

bool manualeject()
   {
      bool ejectOK = false;
      char key = keypad.getKey();
      while(key != '#' && key != '*')
       {
        switch(key)
         {
           case NO_KEY:
           break;
               
           case'1': case'2': case'3': case'A':
           case'4': case'5': case'6': case'B':
           case'7': case'8': case'9':  case'C':
           case'0': case'D':
           break;
         
           case'#':
             ejectOK = true;
           break;
 
           case'*':
             ejectOK = false;
           break;
           
         }
         key = keypad.getKey();
      }
      mainScreen();
      return ejectOK;
    }

Thank you for the assistance evanmars. As you said, the problem was that the key required to toggle the bool variable was also the key used to prevent the switch statement from running. Thank you also gfvalvo for explaining how to auto-format and everyone else for use of code tags.
I have learned much more than expected from this and I will certainly be using the forum again.

Also, If anyone can suggest ways to clean-up the program this would also be very helpful.

bool manualeject()
{
  bool ejectOK = false;
  char key = keypad.getKey();

  while (key != '#')
  {
    switch (key)
    {
      case NO_KEY:
        break;

      case'1': case'2': case'3': case'A':
      case'4': case'5': case'6': case'B':
      case'7': case'8': case'9':  case'C':
      case'0': case'D':
        break;

      case'*':
        ejectOK = !ejectOK;
        lcd.setCursor(15, 2);
        if (ejectOK == true)
        {
          lcd.print("Eject");
        }
        else
        {
          lcd.print("     ");
        }
        break;

        break;

    }
    key = keypad.getKey();
  }
  return ejectOK;
}