memory cost on the loop of menus

I have a question on the wasting of the memory on the use of menus.
What is the task:
I have mainMenu, subMenu1, subMenu2, subMenu3, ...
Entry from mainMenu, and chose 1(or 2, 3,..) to subMenu1. If tasks done, go back to the mainMenu.

The Codes:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void mainMenu(){
//input 1-3 by user
   switch(choice) //choice is the input
   {
     case 1: subMenu1();
             break;
     case 2: subMenu2(); //keep simple, use two sub menus
             break;
     default:
             //blabla...
             break;
   }
   return; //return to main function or whatever upper level
}

void subMenu1(){
   //done something
   mainMenu();
}

//subMenu2 is similar to subMenu1 and has a "mainMenu()" call. 


My problem is:
the call for mainMenu() in subMenus looks like a recursion, which means the memory would be reallocated again for the called maniMenu. Is that right?

If so, times of the memory space for mainMenu function are required if going back to mainMenu several times from subMenus. But what i wanna just a choice and I dont want to wast the memory.

How to avoid the memory cost?thanks.
I think you don't want to call mainMenu() in subMenu1() at all. Just return. After all, when subMenu1() is done, do you really want to prompt the user for a new choice and execute the switch again? If you do, then put a loop around the code in mainMenu().
Ding ding ding! dlhayden has it! Sorry, I'm just bored with typing <username> + 1 so I changed it up.
do you mean something like this?

1
2
3
4
5
6
7
8
9
//in the mainMenu
void mainMenu(){
    while (1){
           cin>>choice;
           switch(choice){
                   //the switch case
           }
     }
}


Thanks for the idea, and I will try.
Well that's at least half the idea, but hey, progress is progress.
Topic archived. No new replies allowed.