>If one of you experienced programmers could look over this and
>tell me if there was a better method of going about this task
I had to define my own clrscr and gotoxy because Borland is crazy about nonstandard functions, but this seems to work peachy except for the off the screen bug:
Code:
void print ( int x, int y )
{
clrscr();
gotoxy( x, y );
printf ( "*" );
}
int main ( void )
{
int key = 0, xval = 40, yval = 12;
printf("Use the arrow keys to move the dot, ENTER to quit: ");
print ( xval, yval );
while ( key != ENTER ) {
switch ( ( key = getch() ) )
{
case UP: print ( xval, --yval ); break;
case DOWN: print ( xval, ++yval ); break;
case LEFT: print ( --xval, yval ); break;
case RIGHT: print ( ++xval, yval ); break;
}
}
return EXIT_SUCCESS;
}
The bug I'll leave to you since it's simple enough to fix with a little extra testing. Upon running your program I noticed that the asterisk tended towards multiplying instead of remaining the only one and while I could move it down and to the right, up and left had problems.
In the case of this program, a loop is drastically easier to follow than goto and one of your switch statements was apparently redundant. If you had a reason for the first one let me know because I removed it. You'll notice that I moved the relocation and printing operation to a single function since you use it quite a bit, this makes the code shorter and a bit more elegant than the way you had it.
Notes:
Please use the code tags from now on, it makes helping you quite a bit easier if we don't have to reformat the code first. And when you paste code, be sure to include the includes as that makes it easier to determine both what platform and compiler you have, but also saves us having to guess or rewrite your code to cover for an unknown feature.
-Prelude