This program seems to work OK except for the "walking" ( function movePen ) part. It gets the commands and prints. The answer is probable right in front of me. Can you give me a clue?

Thanks #include <iostream>

using std::cin;
using std::cout;
using std::endl;

const int PenUp = 1;
const int PenDown = 2;
const int TurnRight = 3;
const int TurnLeft = 4;
const int Move = 5;
const int PrintGrid = 6;
const int Stop = 9;
const int East = 0;
const int South = 1;
const int West = 2;
const int North = 3;
const int Max = 100; /* the maximum number of commands */
const int BoardSize = 20;
const char DrawChar = '*';
const char BlankChar = ' ';

void getCommands(int [][2]);
int turnRight(int);
int turnLeft(int);
bool movePen(bool, int [][BoardSize], int, int);
void printArray(int [][BoardSize]);

main()
{
int floor[BoardSize][BoardSize] = {{0,0}},
command, direction = East,
commandArray[Max][2] = {0,0}, distance = 0, count = 0;
bool error_flag = false,
pen_is_down = false;

getCommands(commandArray);
command = commandArray[count][0];

while (command != Stop && !(error_flag)) {
switch (command) {
case PenUp:
pen_is_down = true;

break;
case PenDown:
pen_is_down = false;
.
break;
case TurnRight:
turnRight ( direction);

break;
case TurnLeft:
turnLeft( direction );

break;
case Move:
movePen (pen_is_down, floor, direction, distance);

break;
case PrintGrid:
printArray (floor);

break;
}
command = commandArray[++count][0];
}
return 0;
}

void getCommands(int commands[][2])
{
int rowmarker = 0, cmd;
char letter;

do{
cout << "Enter command (" << Stop <<" to end input): ";
cin >> cmd;
commands[rowmarker][0] = cmd;
if (cmd == Move){
letter = cin.get(); /* gobble the comma */
cin >> commands[rowmarker][1];
}
rowmarker++;
}while((cmd != Stop) && (rowmarker < Max));
if(cmd != Stop) {
cout << "Too many commands!!\n";
cout << "Last command changed to " << Stop << endl;
commands[Max - 1][0] = Stop;
}
letter = cin.get();
}

int turnRight(int d)
{
static int dir;
++dir;
if (dir=4)
dir = 0;
return d;
}

int turnLeft(int d)
{
static int dir;
--dir;
if (dir=-1)
dir = 3;
return d;
}

bool movePen(bool down, int a[][BoardSize], int dir, int dist)
{
static int row = 0;
static int column = 0;
int count = dist;
int i, colEnd, rowEnd;
int command;
switch (dir){


case East:
colEnd = column + dist;
if (colEnd > 20){
command = Stop;
break;
}


if ( PenDown ) {
for ( i = 0; i < count ; ++i ){
a [ row ][column] = DrawChar;
++ column;}
}
else {
for ( i = 0; i < count ; ++i ){
a [ row ][column] = BlankChar;
++ column;}
}
break;

case West:
colEnd = column + dist;
if (colEnd > 20){
command = Stop;
break;
}


if ( PenDown ) {
for ( i = 0; i < count ; ++i ){
a [ row ][column] = DrawChar;
++ column;}
}
else {
for ( i = 0; i < count ; ++i ){
a [ row ][column] = BlankChar;
++ column;}
}

break;

case South:
rowEnd = row + dist;
if (rowEnd > 20){
command = Stop;
break;
}


if ( PenDown ) {
for ( i = 0; i < count ; ++i ){
a [ row ][column] = DrawChar;
++row;}
}
else {
for ( i = 0; i < count ; ++i ){
a [ row ][column] = BlankChar;
++row;}

}
break;

case North:
rowEnd = row - dist;
if (rowEnd < 0){
command = Stop;
break;
}

if ( PenDown ) {
for ( i = 0; i < count ; ++i ){
a [ row ][column] = DrawChar;
--row;}
}
else {
for ( i = 0; i < count ; ++i ){
a [ row ][column] = BlankChar;
--row;}

}
break;
}

return down;

}

void printArray(int a[][BoardSize]){
int i,j;


for (i =0; i < BoardSize; i++){
for (j = 0 ; j < BoardSize; j++)
cout << a[i][j];
cout << "\n";}
}