1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Problem in C program ?

  1. Aug 29, 2009 #1
    Hi everybody ...

    i hope you are all ok ..

    i have been asked to design a small program that perform the X /O game

    i have done it , but the program quit by itself .. don't know why?

    you can see the code in the attachment http://www.2shared.com/file/7462216/a36b3e8e/X_-_O.html"
     
    Last edited by a moderator: Apr 24, 2017
  2. jcsd
  3. Aug 29, 2009 #2

    sylas

    User Avatar
    Science Advisor

    Because your loop termination condition is not what you want. It will probably terminate after the first move is entered.

    There are several things you can do to make this program work rather better. For a start, it's really helpful to layout the program correctly. Any text book should show the conventions used.

    A simpler design would be to check for a win immediately after each move, and then have the main loop terminate after nine moves.

    Cheers -- sylas
     
    Last edited by a moderator: Apr 24, 2017
  4. Aug 30, 2009 #3
    i always check whether the play satisfy the wining conditions or not .. and this is done after every play .. but i think , as you said , the problem is in the condition of the while loop
    do you have any idea about that ?
     
  5. Aug 30, 2009 #4

    sylas

    User Avatar
    Science Advisor

    Yes. I already suggested my idea. Count the moves.

    If you want to know what your test is doing at the moment, remember that && binds more tightly than ||, and try out some examples on paper. For example, suppose the first move is in position 0,0. What will the loop condition evaluate?

    It would also be a good idea to initialize the board before the game starts, although strictly speaking this isn't necessary with c++.

    Cheers -- sylas
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Problem in C program ?
  1. Base C program problem (Replies: 5)

  2. C programming problem (Replies: 1)

Loading...