Thread: mystery problem

  1. #1
    Registered User Draco's Avatar
    Join Date
    Apr 2002
    Posts
    463

    mystery problem

    I ran into a problem with the program I'm making, where you move a dot around(the one from my last post). I was putting limits so you can't move past the screen, but now I can't move left or up. Right and down still work for me. Can anyone tell what's wrong?

    code::

    #include<stdio.h>
    #include<math.h>
    #include<stdlib.h>

    #define ENTER '\r'
    #define UP 72
    #define DOWN 80
    #define LEFT 75
    #define RIGHT 77

    main()
    {
    int key,xval,yval;

    xval=40;
    yval=12;

    clrscr();
    printf("Use the arrow keys to move the dot, ENTER to quit: ");
    gotoxy(xval,yval);
    printf("*");

    while(key!=ENTER) {
    key=getch();
    if(key==0)
    key=getch();
    else
    break;
    gotoxy(xval,yval); /*added this line after finding it was the key*/
    printf(" ");

    switch(key) {
    case UP:
    while(yval>2) {
    gotoxy(xval,--yval);
    break;
    }
    case DOWN:
    while(yval<25) {
    gotoxy(xval,++yval);
    break;
    }
    case LEFT:
    while(xval>2) {
    gotoxy(--xval,yval);
    break;
    }
    case RIGHT:
    while(xval<78) {
    gotoxy(++xval,yval);
    break;
    }
    }
    printf("*");
    }
    }

  2. #2
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    The mystery problem is why your code tags aren't working.
    The world is waiting. I must leave you now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 03-31-2008, 05:53 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM