Menu Based Programs and Nested Switch.

Nevermind, ty for the replies though.
Last edited on
For each case just call another menu function and if needed pass the function the value of userSelection.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
cout << "Select a team" << endl; 
cin  >> UserSelection; 

  switch (UserSelection)
{
case 1: 
cout << "New England Patriots selected" << endl; 
menu(UserSelection);
break; 
case 2: 
cout << "Buffalo Bills selected" << endl; 
menu(UserSelection);
break; 
case 3: 
cout << "New York Jets selected" << endl;
menu(UserSelection);
break; 
case 4: 
cout << "Miami Dolphins selected" << endl; 
menu(UserSelection);
break; 
Hmmmm, I am not sure of what you mean.

What is menu(UserSelection); doing exactly?

When I type it up in code and define it, there's an error.

"IntelliSense: expression must have (pointer-to-) function type".
I'm not telling you to actually type it that exact code. What I am saying is you can create another function named whatever you want to call it and then invoke it for each switch case. Think of it as a sub-menu that will be called when the first menu is fulfilled. The argument (UserSelection) is being passed to the sub-menu function you create in case you need it. Otherwise you don't have to have a signature(argument) for the sub-menu function.

In the case of menu(UserSelection) , it is a function being called that would contain another sub-menu. You would need to create the function, but it would look something like this.
1
2
3
4
5
6
7
void menu(const string&); // Function Prototype, don't include a signature if you dont need it

void menu(const string& selection)
{
// create another menu here

}
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
int myCaseOneMenu(UserSelection)
{
        //THIS IS A MENU
        // CHOOSE A NUMBER
        return UserSelection;
}
//---
cout << "Select a team" << endl;
cin  >> UserSelection;
 
switch (UserSelection)
{
case 1:
        cout << "New England Patriots selected" << endl;ยด
        myCaseOneMenu(UserSelection);
        switch (UserSelection);
        case 1:
        case 2:
        case 3:
       
break;
case 2:
        cout << "Buffalo Bills selected" << endl;
break;
case 3:
        cout << "New York Jets selected" << endl;
break;
case 4:
        cout << "Miami Dolphins selected" << endl;
break;
I think I'm just trying to ask about nested switch structure. I edited my OP.
case 1: // NESTED CASE 1, CAN'T USE 1 FOR INPUT?

Why wouldn't you be able to use case 1 in the nested switch?
Topic archived. No new replies allowed.