Case 1, Case 2, Case 3........

This is a discussion on Case 1, Case 2, Case 3........ within the C++ Programming forums, part of the General Programming Boards category; How do you use the function case, where right when you press the button it goes to that spot...

  1. #1
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269

    Case 1, Case 2, Case 3........

    How do you use the function case, where right when you press the button it goes to that spot
    Code:
    #if _emo
      #define stereo_type_i_dislike
    #endif

  2. #2
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    That's not very descriptive, but from what I can tell, you're talking about when someone presses a key, it calles a function.

    use this if that IS the case. (If not, I don't care):

    #include <conio.h>

    void main(void)
    {
    getch(variable_name);
    /* then use if statements to determine where, when, and if to go, depending on the value of variable_name. This function will automatically take just 1 character, and then close the input stream. */
    }

    Hope this helped. And if it didnt? I don't care.

    Sean Mackrory
    sean_mackrory@hotmail.com

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Here's one way:
    Code:
    #include <conio.h>
    #include <iostream.h>
    
    int main()
    {
       int answer;
    
       answer = getch();
    
       switch(answer)
       {
          case 'a':
             cout << "User entered a.\n";
             break;
          case 'b':
             cout << "User entered b.\n";
             break;
          //add more cases as necessary
          default:
             //default condition 
             cout << "Not found.\n";
       }
       return 0;
    }
    Use getche() if you want the input echoed.
    Last edited by swoopy; 11-05-2001 at 06:26 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Format Precision & Scale
    By mattnewtoc in forum C Programming
    Replies: 1
    Last Post: 09-16-2008, 11:34 AM
  2. Base converter libary
    By cdonlan in forum C++ Programming
    Replies: 22
    Last Post: 05-15-2005, 02:11 AM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 04:00 PM
  4. Converting Numbers to Words
    By denizengt in forum C Programming
    Replies: 20
    Last Post: 11-05-2003, 09:19 PM
  5. returning to a spot in the code
    By Shadow in forum C Programming
    Replies: 4
    Last Post: 09-22-2001, 06:24 AM

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