code problem

This is a discussion on code problem within the C Programming forums, part of the General Programming Boards category; Im trying to write code for a button that will display a message when pressed then a different message when ...

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    7

    code problem

    Im trying to write code for a button that will display a message when pressed then a different message when pressed again and then another message when pressed again. Then if pressed again it will go back to the first message and so on.

    Code:
    if(BUTTON==DOWN){
    /*code for first display*/
    }
    if(BUTTON==DOWN){
    /*code for second display*/
    }
    if(BUTTON==DOWN){
    /*code for third display*/
    }
    I thought it might be something like this but the program wont know when to go onto the following message. If anyone can help that would be great.

  2. #2
    Registered User
    Join Date
    Mar 2006
    Location
    Antwerp, Belgium
    Posts
    9
    Perhaps a case/switch?

    define another variable like:
    Code:
    int amount=0;
    so when you press the button you would do:
    Code:
    amount++;
    so you can now proceed with the case:

    Code:
    switch(amount)
    {
        case 1: printf("Text1");break;
        case 2: printf("Text2");break;
        case 3: printf("Text3");break;
        default: printf("Default text");
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code problem
    By sybariticak47 in forum C++ Programming
    Replies: 9
    Last Post: 02-28-2006, 11:50 AM
  2. Problem with game code.
    By ajdspud in forum C++ Programming
    Replies: 5
    Last Post: 02-14-2006, 06:39 PM
  3. problem with selection code
    By DavidP in forum Game Programming
    Replies: 1
    Last Post: 06-14-2004, 02:05 PM
  4. Replies: 5
    Last Post: 12-03-2003, 05:47 PM
  5. Help with code for simple Y2K problem
    By Mule in forum C++ Programming
    Replies: 3
    Last Post: 03-06-2003, 12:53 AM

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