c - Calling main menu is displaying sub menu -
i doing airplain seat booking system. here have main menu of chooseflight() , submenu of printmenu(). whenever press 'f' printmenu's options should return mainmenu. cannot. please me!
int main() { chooseflight(); fflush(stdin); return 0; } void chooseflight(void) { char selectflight; printf("a) flight 102 b) flight 311 c) flight 444 d) flight 519 e)quitprogram\n"); scanf("%c",&selectflight); switch(selectflight) { case 'a': puts("welcome flight 102 service"); while(1){ printmenu102(); } break; case 'b': puts("welcome flight 311 service"); printmenu311(); break; case 'c': puts("welcome flight 444 service"); printmenu444(); break; case 'd': puts("welcome flight 519 service"); printmenu519(); break; case 'e': quitprogram(); break; } } void printmenu102() { char lablename; printf("a) show number of empty seats b) show list of empty seats c)show alphabetical list of seats d) assign passenger toa seat e)delete seat assignment f) quittotopmenu\n"); scanf("%c",&lablename); switch(lablename) { case 'a': noofemptyseats102(); break; case 'b': listofemptyseats102(); break; case 'c': alphabeticallistofseats102(); break; case 'd': assingseats102(); break; case 'e': deleteseats102(); break; case 'f': quittotopmenu(); break; } } void quitprogram(void) { exit(exit_failure); } void quittotopmenu(void) { chooseflight(); }
my output is:
a) flight 102 b) flight 311 c) flight 444 d) flight 519 e)quitprogram welcome flight 102 service a) show number of empty seats b) show list of empty seats c)show alphabetical list of seats d) assign passenger toa seat e)delete seat assignment f) quittotopmenu a) show number of empty seats b) show list of empty seats c)show alphabetical list of seats d) assign passenger toa seat e)delete seat assignment f) quittotopmenu f a) flight 102 b) flight 311 c) flight 444 d) flight 519 e)quitprogram a) show number of empty seats b) show list of empty seats c)show alphabetical list of seats d) assign passenger toa seat e)delete seat assignment f) quittotopmenu
the submenu automatically being displayed without staying in main menu.
i hope helps problem:
int main() { //when somthing fails return 0 //else continue if ( !chooseflight() ) { return 0; } fflush(stdin); return 0; } void chooseflight(void) { char selectflight; printf("a) flight 102 \ b) flight 311 \ c) flight 444 \ d) flight 519 \ e)quitprogram\n"); scanf("%c",&selectflight); fflush(stdin); switch(selectflight) { case 'a': puts("welcome flight 102 service"); //when somthing fails return 0 //else return 1 success if ( !printmenu102() ) { return 0; } else { return 1; } break; case 'b': puts("welcome flight 311 service"); printmenu311(); break; case 'c': puts("welcome flight 444 service"); printmenu444(); break; case 'd': puts("welcome flight 519 service"); printmenu519(); break; case 'e': quitprogram(); break; } } void printmenu102() { char lablename; printf("a) show number of empty seats \ b) show list of empty seats \ c)show alphabetical list of seats \ d) assign passenger toa seat \ e)delete seat assignment \ f) quittotopmenu\n"); scanf("%c",&lablename); fflush(stdin); switch(lablename) { case 'a': noofemptyseats102(); break; case 'b': listofemptyseats102(); break; case 'c': alphabeticallistofseats102(); break; case 'd': assingseats102(); break; case 'e': deleteseats102(); break; case 'f': //success return 1; break; } } void quitprogram(void) { exit(exit_failure); } void quittotopmenu(void) { chooseflight(); }
Comments
Post a Comment