Menu Driven Program - Sample driver


/* includes */

/* defines */

#define QUIT 5

/* prototypes for functions defined in the same file as main() */


int main(void) 
{
  /* declarations */
  int choice;

  do
  {
    print_menu();
    get_int_bound(&choice, 1, QUIT); /* assumes 5 options with 5 being quit */
    switch(choice)
    {
      case 1: /* do whatever is appropriate */
              break;
      
      case 2: /* do whatever is appropriate */
              break;
      case 3: /* do whatever is appropriate */
              break;
      case 4: /* do whatever is appropriate */
              break;
      case QUIT: printf("\nYou have chosen to quit - Exiting program. \n\n");   
    }
  }
  while (choice != QUIT);

  return (0);
}

/***
NOTE: I defined QUIT to be 5 so that I could use the word QUIT in my
   switch statement instead of the value 5.  The QUIT is more readable than
   5.  I could also define words for the other options if I wanted.
***/