If I run the program, and select q, it will quit correctly. If I select e it goes to the edit menu but prints it twice. If I then select q it goes to the main menu and prints the default case, "please select from menu", then prints the main menu again. If I select q now, it goes to the edit menu, not quitting the program like it did before. So now it's stuck in a loop between main and edit when I select q.

#include <stdio.h>  
#include <stdlib.h>

void edit(void){

printf ("\nEDIT MENU\n");
printf ("  (a)Add\n");
printf ("  (p)Display\n");
printf ("  (i)Reutrn\n");
printf ("  (o)Check Out\n");
printf ("  (d)Delete\n");
printf ("  (q)Main Menu\n");


char choice;
scanf ("%c",&choice); 

switch (choice) {

case 'a':
  system("./add");
  break;
  

case 'p':
  system("./display");
  break;

case 'i':
  system("./return");
  break;

case 'o':
  system("./checkout");
  break;

case 'd':
  system("./delete");
  break;

case 'q':
  main();

default:
  edit();

}

}

void reports(void)
{

}

void add(void)
{
}

void del(voi)
{
}

int main(void){

	
printf ("MAIN MENU\n");
printf ("  (e)Edit\n");
printf ("  (r)Reports\n");
printf ("  (q)Quit\n");

char choice;
scanf ("%c",&choice); 

switch (choice) {
  case 'e':
  edit();
  break;
  
  
  case 'r':
  reports();
  break;
  

  case 'q':
  break;

  default: 
  printf("Choose from the menu\n");
  main();
}
return 0;
}

Edited 7 Years Ago by Mattpd: n/a

You shouldn't be calling main() like that. In your main() turn your menu into a while loop and call your functions from within. In your function (edit) when the user hits q, just use return; to go back to main.

This article has been dead for over six months. Start a new discussion instead.