How come this statement not work?

This is a discussion on How come this statement not work? within the C++ Programming forums, part of the General Programming Boards category; I am trying to get the object (@) able to move up, down, left, and right but i made a ...

  1. #1
    why
    Guest

    How come this statement not work?

    I am trying to get the object (@) able to move up, down, left, and right but i made a mistake couple places in this code (below) will someone tell me whats wrong????




    #include
    #include
    #include
    const char K_DOWN = 0x50;
    const char K_LEFT = 0x4B;
    const char K_UP = 0x48;
    const char K_RIGHT = 0x4D;
    int main(void)
    {
    char c=0;
    while(c != 27)
    {
    c=getch();

    if(c==K_DOWN)
    {


    gotoxy(x,y);
    putch(" ");
    y++++;
    gotoxy(x,y);
    putch("@")

    }

    if(c==K_UP)

    {

    gotoxy(x,y);
    putch(" ");//get rid of tracks
    y----;
    gotoxy(x,y);
    putch("@")
    }
    if( c== K_RIGHT)
    {
    gotoxy(x,y);
    putch(" ");//get rid of tracks
    x++++;
    gotoxy(x,y);
    putch("@")
    }
    if(c==K_LEFT)
    {
    gotoxy(x,y);
    putch(" ");//get rid of tracks
    x----;
    gotoxy(x,y);
    putch("@")
    }
    }
    return(0);
    }

  2. #2
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    523

    What the f*** is that?

    y++++;
    Whats that do? is it legal? is it what you mean?
    never seen that!!
    All spelling mistakes, syntatical errors and stupid comments are intentional.

  3. #3
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,738
    yeah, y++++ and x++++ probably wont work. try this:

    y += 2

    and

    x+= 2
    My Website

    "Circular logic is good because it is."

  4. #4
    Unregistered
    Guest
    #include
    #include
    #include
    const char K_DOWN = 0x50;
    const char K_LEFT = 0x4B;
    const char K_UP = 0x48;
    const char K_RIGHT = 0x4D;
    int main(void)
    {
    char c=0;
    while(c != 27)
    {
    c=getch();

    if(c==K_DOWN)
    {


    gotoxy(x,y);
    putch(" ");
    y++;
    gotoxy(x,y);
    putch("@")

    }

    if(c==K_UP)

    {

    gotoxy(x,y);
    putch(" ");//get rid of tracks
    y--;
    gotoxy(x,y);
    putch("@")
    }
    if( c== K_RIGHT)
    {
    gotoxy(x,y);
    putch(" ");//get rid of tracks
    x++;
    gotoxy(x,y);
    putch("@")
    }
    if(c==K_LEFT)
    {
    gotoxy(x,y);
    putch(" ");//get rid of tracks
    x--;
    gotoxy(x,y);
    putch("@")
    }
    }
    return(0);
    }




    can you fix that so it works?

  5. #5
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    523
    One thing I can see is putch("@");
    putch is for characters not strings so try using:

    putch('@');

    single quotes for characters
    double quotes for strings

    You may have other errors, as I haven't looked to closely because you didn't use code tags(see FAQ).
    All spelling mistakes, syntatical errors and stupid comments are intentional.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Will too much IF STATEMENT decrease performance
    By beyonddc in forum C++ Programming
    Replies: 10
    Last Post: 04-18-2011, 02:07 PM
  2. Meaning of this statement?
    By @nthony in forum C Programming
    Replies: 7
    Last Post: 07-16-2006, 02:57 AM
  3. capture card wont work with xp
    By scott27349 in forum Tech Board
    Replies: 6
    Last Post: 02-08-2005, 08:47 PM
  4. If you are employed as a programmer, please look
    By Flood Fighter in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 09-28-2004, 02:35 AM
  5. If statement for identical integer
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 04-03-2002, 07:49 AM

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