C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 10-31-2009, 07:03 PM   #1
Registered User
 
Join Date: Oct 2009
Posts: 7
Do..While in a Switch

Well. I'm having a little bit of an issue, and I'm taking it's just from my absolute lack of experience with C++ atm. But hey, lets give this a go. So, I'm constructing a little menu system. So, I'm using the Do..While statement, while in one itself. (Mind you, I'm still on the first few lessons, but I'm still fiddling around with them. So I'll gladly take some advice on better methods, though I'm not sure if I'll understand it at this time.) So here's my code so far.

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 );
}
}
So, this code is quite incomplete. I'm still at the first stage of making it. Basically, (it's supposed to) work like this:

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   Reply With Quote
Old 10-31-2009, 08:11 PM   #2
C\C++ beginner
 
Masterx's Avatar
 
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:
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning."
Rick Cook

Quote:
"...a computer is a stupid machine with the ability to do incredibly smart things, while
Quote:

computer programmers are smart people with the ability to do incredibly stupid things. They are,
in short, a perfect match.."
Bill Bryson

Masterx is offline   Reply With Quote
Old 11-01-2009, 06:18 AM   #3
Registered User
 
Join Date: Oct 2009
Posts: 7
Wow, that's just awful. Thanks. xD
MPQC is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 02:26 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22