hi...
can someone help me with this codde its a turtle graphics problem which im sure you guys have heard of..
iam getting one error ........i dont know what iam doing wrong...could you please check the logic of this code and try to correct it..that would be great.
i am using visual C++ v6.0 and the error i receive is :
c:\turtle.cpp(229) : fatal error C1004: unexpected end of file found
1 error.. this error is pointing to line 229.
//turtle.cpp
//This program uses a double dimension array to draw shapes and lines base on the users input of commands
#include <iostream.h>
int func_name();
int func_game();
int commands;
//direction commands
const int right = 1;
const int left = -1;
int main(void)
{
char yesorno; //user response
func_name(); //call function func_name()
Again: //repeat process
func_game(); //call function func_game()
cout<<"Would you like to play again? (y/n)";
cin>>yesorno;
cout<<endl<<endl;
if (yesorno=='y')
{
cout<<endl<<endl;
goto Again;
}
else
cout<<"Thanks for using my program. Please come again sometime soon.";
cout<<endl<<endl;
return 0;
} //end main
// **************************************************
//This part of the program just allows the user to enter their name
int func_name()
{
char f_name[20];
cout<<"Hello, and welcome to my game!";
cout<<endl;
cout<<"Please input your first name. ";
cin>>f_name;
char l_name[30];
cout<<"Please input your last name. ";
cin>>l_name;
cout<<endl;
cout<<"Welcome "<<f_name<<" "<<l_name<<" I hope you have fun with my game!";
cout<<endl<<endl<<endl;
return 0;
}
// **************************************************
//This is the actual game part of the program that uses the double dimension array
int func_game()
{
char floor[20][20];
int row = 0, col = 0, spaces, stop=0, ncols = (int)(floor), direction = right;
bool down = false;
cout<<"Instructions: The purpose of the game will use you to input commands to make a ";
cout<<endl;
cout<<"picture using * and blank spaces. A list of what the commands do will be above ";
cout<<endl;
cout<<"the command space to enter.";
cout<<endl<<endl;
cout<<"The commands: ";
cout<<endl;
cout<<"1-pen up";
cout<<endl;
cout<<"2-pen down";
cout<<endl;
cout<<"3-Turn right";
cout<<endl;
cout<<"4-Turn left";
cout<<endl;
cout<<"5,#-Amount of spaces moved ";
cout<<endl;
cout<<"6-Prints game on screen";
cout<<endl;
cout<<"9-Ends data ";
cout<<endl<<endl;
//Default:
//cout<<"Please input your command: ";
//cin>>commands;
//cout<<endl;
cout<<"Please enter your choice?";
cin>>commands;
if(commands == 9)
{
cout<<"Good Bye\n"; //exit
return 0;
}
switch (commands)
{
case 1: down = false;
commands=0;
//goto Default;
break;
case 2: down = true;
commands=0;
//goto Default;
break;
case 3: if (direction == right)
{
direction = ncols ;
}
else
{
if(direction== ncols)
{
direction = left;
commands=0;
}
else {
if (direction == left)
{
direction = -ncols;
}
else
direction = right;
//goto Default;
break;
case 4: if (direction == left)
{
direction= -ncols;
}
else
if(direction == -ncols)
{
direction = right;
} else
if (direction == right)
{
direction = ncols;
}
else
direction = left;
commands=0;
//goto Default;
break;
case 5:
cout<<"How many spaces would you like to move? ";
cin>>spaces;
//int spaces = commands++;
int j;
for(j = 0; j<spaces; j++)
{
col += direction;
if(col < 0)
{
col -= direction;
if(--row < 0)
row = 20;
}
else {
if(col >= ncols)
{
col -= direction;
if(++row == 20)
row = 0;
}
if(down)
floor [row][col] = '*';
}
//turtle[R][C]=pen;
cout<<endl<<endl;
//goto Default;
break;
//print array
case 6:
for(row=0; row<20;row++)
{
for(col=0; col<20; col++)
{
cout<<floor[row][col]<<" * ";//you'll see
}
cout<<endl;
}
cout<<endl<<endl;
//goto Default;
break;
default:
cout<<"You entered a wrong number please type a correct number. ";
cout<<endl<<endl;
break;
}//end switch
//*************************************************//
cheers,
kashif