The elements of a menu I'm creating are not fixed. With that I mean that some option will be available only if special conditions are met. A regular menu is easy create. You just assign a value to each option and with a Switch Statement you choose the option the user selected. In my menu, the user could see
1. Option A , 2. Option B , 3. Option C , 4. Option D
OR
1. Option A , 2. Option C , 3. Option D
Can someone direct me to a topic that presents a way to create menus like the one I want?
A solution I thought is have a unique variables(a1,a2,...) assigned to each option (starting values = 0). When the conditions for an option are met a variable x=1 is typed, followed by the Option text
1 2 3
|
cout << x << ". " << "Option A";
a1 = x;
x++;
|
1 2 3
|
cout << x << ". " << "Option C";
a3 = x;
x++;
|
That way I can have each number(1,2,..) next to an option tied to the corresponding variable and then, using a switch I can have the selected option executed.
1 2 3 4 5
|
cin >> choice;
switch (choice){
case a1:...
case a2:...
...
|
I would appreciate any thoughts about the solution I thought of or any other you have to suggest.
PS: If you find the time take a look in another question I posted some days ago.
http://www.cplusplus.com/forum/beginner/30691/