![]() |
| | #1 |
| Registered User Join Date: Oct 2009
Posts: 7
| Do..While in a Switch Code: #include <iostream>
using namespace std;
int main()
{
int input;
int menu1;
int menu2;
int menu3;
int menu4;
int menu5;
menu1 = 0;
menu2 = 0;
menu3 = 0;
menu4 = 0;
menu5 = 0;
do
{
cout<<"Choose an Option.\n";
cout<<"1. Option 1.\n";
cout<<"2. Option 2.\n";
cout<<"3. Option 3.\n";
cout<<"4. Option 4.\n";
cout<<"5. Option 5.\n";
cout<<"0. Exit.\n";
cout<<"Selection: ";
cin>>input;
}while (input != 0);
switch ( input ) {
case 1:
do
{
cout<<"1. Sub1 Option 1.\n";
cout<<"2. Sub1 Option 2.\n";
cout<<"3. Sub1 Option 3.";
cout<<"4. Sub1 Option 4.";
cout<<"5. Sub1 Option 5.";
cout<<"9. Exit.";
cin>> menu1;
}while ( menu1 != 9 );
}
}
You choose option 1, it brings to a submenu. Then, you can choose one of the sub-submenu's. In the end, it'll be similar to a pyramid. So a quick explanation of the variables. Input is the main input - for the first menu. Then, Menu1 controls the first submenu. So from the code I have, in essence, at the end, I could put }while ( menu != 9 && input != 0 ) and I (believe) it would still work out. It's just running both subs. But, when I run this code, it doesn't move on from one menu to another. (Though I've only done the first sub-menu.) So when I push 1, it should move to the first case, but it doesn't. So what have I got wrong, here? |
| MPQC is offline | |
| | #2 | |||
| C\C++ beginner Join Date: Nov 2007 Location: Somewhere nearby,Who Cares?
Posts: 384
| because you are still in the first loop . why ? look at your while continuation condition! it says ! until 0! loop! you chose 1! so it is still not zero! loop continues!
__________________ Quote:
Quote:
Quote:
Bill Bryson | |||
| Masterx is offline | |
| | #3 |
| Registered User Join Date: Oct 2009
Posts: 7
| Wow, that's just awful. Thanks. xD |
| MPQC is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Data Structure Eror | prominababy | C Programming | 3 | 01-06-2009 09:35 AM |
| ascii rpg help | aaron11193 | C Programming | 18 | 10-29-2006 01:45 AM |
| Switch | cogeek | C Programming | 4 | 12-23-2004 06:40 PM |
| Switch Case | FromHolland | C++ Programming | 7 | 06-13-2003 03:51 AM |