Code:
#include <stdio.h>
#define MAX_HEIGHT 20
#define MAX_LENGTH 20
#define TRUE 1
#define FALSE 0
/*function prototype*/
int mainMenu ( char[][] );
/*main function - begins program execution -----------------------------------*/
int main ( void )
{
char board[ MAX_HEIGHT ][ MAX_LENGTH ] =
{
{ '0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0' },
{ '0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0' },
{ '0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0' },
{ '0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0' },
{ '0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0' },
{ '0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0' },
{ '0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0' },
{ '0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0' },
{ '0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0' },
{ '0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0' },
{ '0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0' },
{ '0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0' },
{ '0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0' },
{ '0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0' },
{ '0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0' },
{ '0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0' },
{ '0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0' },
{ '0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0' },
{ '0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0' },
{ '0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0' }
};
mainMenu ( board );
getchar(); /*freeze console output window*/
return 0; /*return value from int main*/
}
/*function to display the main menu*/
int mainMenu ( char bd[][ 20 ] )
{
int choice = TRUE;
int penUp = TRUE;
int i, j;
do
{
printf("\tTURTLE LOGO GRAPHICS\n\n"
"1 Place Pen Up\n"
"2 Place Pen Down\n"
"3 Draw\n"
"4 Show Grid\n"
"5 Quit\n"
"> ");
scanf("%d", &choice);
switch ( choice )
{
case 1:
if ( penUp == TRUE )
{
puts("\nThe pen is already up\n");
}
if ( penUp == FALSE )
{
penUp = TRUE;
puts("\nThe pen has been raised up\n");
}
break;
case 2:
if ( penUp == FALSE )
{
puts("\nThe pen is already down\n");
}
if ( penUp == TRUE )
{
penUp = FALSE;
puts("\nThe pen has been placed down\n");
}
break;
case 3:
if ( penUp == TRUE )
{
puts("\nYou cannot draw with the pen raised up\n");
}
else
{
// This is my trouble part:
printf("Enter the xy coordinates to draw: ");
scanf("%d", &bd[ MAX_HEIGHT ][ MAX_LENGTH ]);
}
break;
case 4:
puts("\n");
for ( i = 0; i < MAX_HEIGHT; i++ )
{
for ( j = 0; j < MAX_LENGTH; j++ )
printf("%c", bd[ i ][ j ]);
printf("\n");
}
puts("\n");
break;
case 5:
return 0;
break;
default:
printf("\n\n");
break;
}
} while ( choice );
}