Thread: After the switch statement?

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    465

    After the switch statement?

    Code:
    #include <cstdlib>
    #include <iostream>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        char namen[100];
        int initial;
        int strength;
        int agility;
        int defense;
        
        cout<<"What would you like to do?";
        cout<<"\n1.New game\n2.Load game\n3.Exit\n";
        cin>>initial;
        switch(initial){
        case 1:
        cout<<"Enter your name:";
        cin>>namen;
        cout<<namen<<" is it. Alright then";
        cout<<"Enter your strength agility and defense(must=20):\n";
        cin>>strength>>agility>>defense;
        if(strength+agility+defense==20)
        cout<<"\nyay!\n";
        break;
        case 2:
        cout<<"Not availiable yet";
        break;
        case 3:
        return 0;
        break;
        default:
        cout<<"error";
        }
        cout<<"                        Welcome to naushmien\n\n*Dramatic Music*\n\n";
        
        
        
        
        system("PAUSE");
        return EXIT_SUCCESS;
    }
    This is the code from my MUD. I need to know how to make it so case 2 and 3 don't display all the code after the switch statment
    for now. When I actually implement loading I want it to display the code after the switch.
    My computer is awesome.

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    return 0;

    How about using some indentation in your code?

  3. #3
    Registered User
    Join Date
    Dec 2004
    Posts
    465
    How do I make it stop so they can read it? Then have it exit. I thought about system pause, but I remember someone telling me not to use it.
    What parts of the code do I indent?
    My computer is awesome.

  4. #4
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    What parts of the code do I indent?
    Your compiler should take care of it, if it doesn't then I suggest an upgrade.
    How do I make it stop so they can read it?
    Look at
    http://faq.cprogramming.com/cgi-bin/...&id=1043284392
    and
    http://faq.cprogramming.com/cgi-bin/...&id=1043284392
    One, of those might serve you well

  5. #5
    Registered User
    Join Date
    Sep 2004
    Posts
    39
    Not sure if this is what you need but why not use a bool? If they enter case 3 then set bool true then do an if statement to see if the bool is true or false. Hope it helped in a way

  6. #6
    Registered User
    Join Date
    Dec 2004
    Posts
    465
    The first one isn't what I needed. The second on helped, but I don't see where I am supposed to specify the time in seconds or something like that. That is in C right? I don't know the slightest bit of C so I don't know how to convert it to C++.
    My computer is awesome.

  7. #7
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    cin.ignore(100); //skips over up to 100 characters that might still be in the input stream
    cin.get(); //waits for the user to enter one character, so if the user hits any key, the program will end.

  8. #8
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    The second on[e] helped, but I don't see where I am supposed to specify the time in seconds or something like that.
    I would suggest re-reading a tutorial on functions and then re-read the page I showed you. It should answer your question.

  9. #9
    Registered User
    Join Date
    Dec 2004
    Posts
    465
    Sorry, 7stud but that doesn't help. I put it in the program, but instead of going on to the code after the switch right away it did after I hit button?
    My computer is awesome.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Mutli Switch statement help
    By elwad in forum C Programming
    Replies: 9
    Last Post: 05-09-2009, 03:19 AM
  2. Switch statement / default:
    By kcpilot in forum C Programming
    Replies: 4
    Last Post: 12-02-2008, 03:14 PM
  3. switch statement
    By guillermoh in forum C Programming
    Replies: 5
    Last Post: 03-10-2008, 02:17 PM
  4. char switch statement
    By jmarsh56 in forum C++ Programming
    Replies: 7
    Last Post: 05-03-2006, 05:04 PM
  5. Efficiency with the switch() statement...
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 10-14-2001, 02:47 PM