Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,549 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,567 people online right now. Registration is fast and FREE... Join Now!




menu switch

 
Reply to this topicStart new topic

menu switch, problems with switch

goshwhyisitsocomplicated_1
21 Nov, 2007 - 11:32 AM
Post #1

New D.I.C Head
*

Joined: 8 Oct, 2007
Posts: 3


My Contributions
the compiler says there are errors with the brackets but I think my while statements may be wrong!!! Is the first time i try switch menus

CODE

#include "Inventory_Class.h" //Inventory Class
#include "Dynamic_Stack.h" //Dynamic Stack Class
#include "Dynamic_Queue.h" //Dynamic Queue Class

#include<iostream>
using namespace std;

void displayMenu()
{
        cout<<"\n        Main Menu\n\n";
        cout<<" S) Choose S for STACK Inventory \n";
        cout<<" Q) Choose Q for QUEUE Inventory \n";
        cout<<" E) Exit Menu \n";
        cout<<"      Enter Your Choice: ";
}

int main()
{
    Inventory myinv;
    char choice;

    Dynamic_Stack<Inventory> invstack;
    
    do
    {
        displayMenu();
        cin>>choice;
        if(choice == 'q' || choice == 'Q')
        {
            switch(choice)
            {
                case 's':
                case 'S': cout<<" You have chosen the Stack Inventoy \n";
                          cout<<" A. Enter A to Push inventory data \n";
                          cout<<" B. Enter B to Pop inventory data \n";
                          cout<<" C. Enter C to Display \n";
                          cout<<" X. Enter X to Exit \n";
                          cin>>choice;    
                    break;
                        switch(choice)
                        {
                            case 'a':
                            case 'A': cout<<" Enter serial # \n";
                                      myinv.getSerial();
                                      cout<<" Enter the manufacturing date day/mth/year \n";
                                      myinv.getDate();
                                      cout<<" Enter the lot number for the part \n";
                                      myinv.getLot();
                                      cout<<" Pushing values...\n";
                                      invstack.push(myinv);
                                      myinv.display();
                                      break;
                            case 'b':
                            case 'B': cout<<" Popping values....\n";
                                      invstack.pop(myinv);
                                       myinv.display();
                                      break;
                            case 'c':    
                            case 'C': cout<<" Displaying Information \n";
                                      myinv.display(); //******
                                      break;
                            case 'x':
                            case 'X': cout<<" Go back to Main Menu \n";
                                       break;
                        }
            }
            //while(choice !='x' || choice!= 'X');
        }
        //}
        //do
        //{
        Dynamic_Queue<Inventory> invQueue;
        if(choice =='q' || choice =='Q')
        {
                
                switch(choice)
                {
                    case 'q':
                    case 'Q': cout<<" You have chosen QUEUE INVENTORY \n";
                              cout<<" E. Enter E to Enqueue an object \n";
                              cout<<" D. Enter D to Dequeue an object \n";
                              cout<<" Z. Enter Z to Exit \n";
                              cin>>choice;
                              break;

                            switch(choice)
                            {
                                case 'e':
                                case 'E': cout<<" Enter serial # \n";
                                          myinv.getSerial();
                                          cout<<" Enter the manufacturing date day/mth/year \n";
                                          myinv.getDate();
                                          cout<<" Enter the lot number for the part \n";
                                          myinv.getLot();
                                          cout<<" Enqueuing values...\n";
                                          invQueue.enqueue(myinv);
                                          myinv.display();
                                          break;
                                case 'd':
                                case 'D': cout<<" Dequeuing values...\n";
                                           invQueue.dequeue(myinv);
                                          myinv.display();
                                             break;
                                case 'z':
                                case 'Z':  cout<<" Go back to main menu \n";
                                           break;
                            }
                            
                }    
        }
    }while(choice !='z' || choice!= 'Z');
}






















User is offlineProfile CardPM
+Quote Post

no2pencil
RE: Menu Switch
21 Nov, 2007 - 11:38 AM
Post #2

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 7,127



Thanked: 76 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
QUOTE(goshwhyisitsocomplicated_1 @ 21 Nov, 2007 - 01:32 PM) *

the compiler says there are errors with the brackets but I think my while statements may be wrong!!! Is the first time i try switch menus

CODE

switch(choice)
            {
                case 's':
                case 'S': cout<<" You have chosen the Stack Inventoy \n";
                          cout<<" A. Enter A to Push inventory data \n";
                          cout<<" B. Enter B to Pop inventory data \n";
                          cout<<" C. Enter C to Display \n";
                          cout<<" X. Enter X to Exit \n";
                          cin>>choice;    
                    break;
                        switch(choice)


The 2nd input of choice is going to screw up your 1st switch statement. Rename that 2nd variable & it should work a little better.

I would suggest trying to avoid using a switch within a switch.
User is online!Profile CardPM
+Quote Post

goshwhyisitsocomplicated_1
RE: Menu Switch
21 Nov, 2007 - 03:12 PM
Post #3

New D.I.C Head
*

Joined: 8 Oct, 2007
Posts: 3


My Contributions
QUOTE(no2pencil @ 21 Nov, 2007 - 12:38 PM) *

QUOTE(goshwhyisitsocomplicated_1 @ 21 Nov, 2007 - 01:32 PM) *

the compiler says there are errors with the brackets but I think my while statements may be wrong!!! Is the first time i try switch menus

CODE

switch(choice)
            {
                case 's':
                case 'S': cout<<" You have chosen the Stack Inventoy \n";
                          cout<<" A. Enter A to Push inventory data \n";
                          cout<<" B. Enter B to Pop inventory data \n";
                          cout<<" C. Enter C to Display \n";
                          cout<<" X. Enter X to Exit \n";
                          cin>>choice;    
                    break;
                        switch(choice)


The 2nd input of choice is going to screw up your 1st switch statement. Rename that 2nd variable & it should work a little better.

I would suggest trying to avoid using a switch within a switch.



thanks
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/7/09 09:39PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month