Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am doing an airplain seat booking system. Here I have a main menu of chooseflight() and submenu of printmenu(). Whenever I press 'f' from printmenu's options I should return to mainmenu. But I cannot. Please help me!

Objective-C
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 to flight 102 service");
             while(1){
             printmenu102();
             }
             break;
             case 'b':
             puts("Welcome to flight 311 service");
             while(1){
             printmenu311();
             break;
             }
             case 'c':
             puts("Welcome to flight 444 service");
             while(1){
             printmenu444();
             }
             break;
             case 'd':
             puts("Welcome to flight 519 service");
             while(1){
             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 a passenger toa seat e)Delete a 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

a

Welcome to flight 102 service

a) Show number of empty seats b) Show list of empty seats c)Show alphabetical list of seats d) Assign a passenger toa seat e)Delete a seat assignment f) Quittotopmenu

a) Show number of empty seats b) Show list of empty seats c)Show alphabetical list of seats d) Assign a passenger toa seat e)Delete a 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 a passenger toa seat e)Delete a seat assignment f) Quittotopmenu
Posted
Updated 17-Aug-14 10:58am
v2
Comments
[no name] 17-Aug-14 18:53pm    
The most likely reason is probably your use of unnecessary infinite loops in your chooseflight function.

1 solution

Hi,

After scanf() statement in main menu & submenu, place getchar(); or fflush(stdin);. Then your code will work perfectly as per your requirement.
 
Share this answer
 
Comments
Jeevan83 18-Aug-14 4:46am    
Thanks worked!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900