Thread: help in tic tac toe with looping only

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    3

    help in tic tac toe with looping only

    i was required to build two player Tic Tac Toe Game in Dos mode.
    but there is some error in my code..can any body help me pls.. i very depressed abt my assignment i am workin on it 4 a week and i dont know wahts wrong with it. can some one kindly coorrect m code.. thanks a ton

    Requirements:

    You cannot use arrays in this assignment.
    There will be nine boxes on the screen numbered from 1 to 9. Game should prompt the player number who has the next turn and ask that player to enter a number between 1 and 9. If the user enters a number of a box which is already occupied, the game will give an error and ask the user to re-enter his move.
    Both players will use the keyboard to input their move, one by one.
    Computer should tell whether the game ended successfully either in draw or Success of any player.
    Game can be ended at any time if any player enters zero. But computer should prompt the message either you want to quit or resume the game.
    There will be only one undo move. undo will be done if any player enters -1. Then his last move should be removed from the board and he should be prompted to enter the move again.
    The game should ask the names of both players at the start.
    Move of player 1 should be indicated on the board by a O and move of player 2 should be indicated by X
    Your should write separate function to check a move for validity, another function to check if a player has won or if the game is draw, another function to input player names, and any other functions that you can make.
    Your main function should have a loop that should take user moves and perform the functions accordingly. "

  2. #2
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    What, pray tell, is your error?
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  3. #3
    Registered User
    Join Date
    Nov 2003
    Posts
    3

    help with tic tac toe

    the program do not accept (-1) statement to undo.. secondly c++ compiler cant compile it... it is givin error that un expected end of file right b4 main()

  4. #4
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Code:
    string 'box1'=" ",'box2'=" ",'box3'=" ",'box4'=" ",'box5'=" ",'box6'=" ",'box7'=" ",'box8'=" ",'box9'=" ";
    The variable names should not have single quotes around them.


    Code:
    	if (con==6)
    void win();
    	 while ((win==1||win==2||win==0)!){
    What exactly does the call void win() aim to achieve? It appears to be a function prototype, but you cannot have these within other functions.

    There are too many errors to quote them all, and your program structure also needs working on. Grab some paper and hash out a structure, then start coding.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  5. #5
    Registered User
    Join Date
    Nov 2003
    Posts
    3

    thanks

    thanks alot... actauuly i m new to progamming and it take me lots of time to uinderstand things
    thanks for tellin that there are many errors in it
    i knew that cuz usually my code have alot.
    thanks again
    but can u explain the logical of (-1) that is to undo any move

  6. #6
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    To undo a move, you must know what the last move was. So, you should have a variable that contains the index of the last square that had an item placed in it. When the user specifies UNDO, just erase the item from that square.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    I guess the first lesson for you is that you should not write 350 lines of code before pressing compile.

    Work in small units you can manage - say 10 lines max. If you get an error after adding 10 new lines, you've got a pretty good idea that the new problem is in the new 10 lines.
    Same with testing, make sure they work before adding more stuff.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help me with my simple Tic tac toe prog
    By maybnxtseasn in forum C Programming
    Replies: 2
    Last Post: 04-04-2009, 06:25 PM
  2. Tic Tac Toe program
    By muzihc in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 08:08 PM
  3. Tic Tac Toe Neural Network
    By glo in forum General AI Programming
    Replies: 4
    Last Post: 06-15-2008, 03:39 PM
  4. Tic Tac Toe... so close...
    By SlayerBlade in forum C Programming
    Replies: 14
    Last Post: 10-10-2005, 08:58 PM
  5. Help with Tic Tac Toe game
    By snef73 in forum C++ Programming
    Replies: 1
    Last Post: 04-25-2003, 08:33 AM