turtle graphics problem??

This is a discussion on turtle graphics problem?? within the C++ Programming forums, part of the General Programming Boards category; hi... can someone help me with this codde its a turtle graphics problem which im sure you guys have heard ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    19

    turtle graphics problem??

    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
    Last edited by atif; 04-29-2002 at 04:39 PM.

  2. #2
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    Use code tags please... I dint even read your prog.

  3. #3
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Posts
    408
    code tags and PLEASE write the errors! Are you really expecting people to find it themselves???

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem in c graphics
    By maifs in forum C Programming
    Replies: 1
    Last Post: 04-02-2009, 06:04 AM
  2. Problem with BGI graphics: Linker Error
    By darklord1984 in forum C++ Programming
    Replies: 9
    Last Post: 11-10-2007, 10:16 AM
  3. Bin packing problem....
    By 81N4RY_DR460N in forum C++ Programming
    Replies: 0
    Last Post: 08-01-2005, 05:20 AM
  4. turtle graphics
    By korbbd in forum C++ Programming
    Replies: 0
    Last Post: 03-06-2002, 02:14 PM
  5. Graphics Problem
    By drdroid in forum C++ Programming
    Replies: 5
    Last Post: 02-27-2002, 01:37 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21