Thread: Input Question

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    2

    Input Question

    Code:
        clear_screen();
        cout << "(S)tart a New Game\n";
        cout << "(L)oad a Game\n";
        cout << "(Q)uit\n";
        choice=getch();
        switch(choice) {
        case 's'||'S':
             NewGame();
             break;
        default:
                cout << "You Must Pick 'S', Restarting";
                main();
                break;
                }
    Basicly I need the switch to recognize both 's' and 'S', incase user has capslock on, I've done it before but I'm just getting back to Programming and I can't remember how it was done.

    Code:
    case 's' || 'S':
    obviously doesn't work, do have to parse all the input into lower case? I thought there was a really simple way, but it's been 2 years.

    Thanks in advance

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    470
    Basicly I need the switch to recognize both 's' and 'S', incase user has capslock on, I've done it before but I'm just getting back to Programming and I can't remember how it was done.
    There are a lot of ways.
    You could try
    Code:
    switch(choice)
    {
         case 's':          // fall through
         case 'S':
                  NewGame();
                  break;
    };
    Another way is to convert the 's' into upper case and then switch on the upper case 's'.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    FYI - Recursively calling main is illegal in C++. Consider using a loop and a bool variable or moving everything in your main function into a separate function of your own that does the same thing.

  4. #4
    Registered User
    Join Date
    Sep 2005
    Posts
    2
    Awesome, that's what I was looking for, the 2 Case lines.

    And as for calling main, I remembered that, I've already started organizing the code better, I call menu now with the improved switch.

    Thanks both of ya.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie Question: File Input and Relative Paths
    By Ashes999 in forum C++ Programming
    Replies: 11
    Last Post: 05-23-2003, 04:21 AM
  2. Replies: 2
    Last Post: 05-12-2003, 04:40 PM
  3. quick question: File Input
    By meltingdude in forum C Programming
    Replies: 1
    Last Post: 04-08-2003, 02:02 AM
  4. Replies: 2
    Last Post: 03-15-2002, 01:45 PM
  5. Handling input errors, general question
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 11-08-2001, 06:21 PM