Solving C Program Problem: X/O Game Quitting Unexpectedly

  • Thread starter Thread starter M.M.M
  • Start date Start date
  • Tags Tags
    Program
AI Thread Summary
The discussion revolves around troubleshooting a C program designed for the X/O game that unexpectedly quits. The main issue identified is related to the loop termination condition, which likely causes the program to exit after the first move. Suggestions include checking for win conditions after each move and counting the total moves to ensure proper game flow. Additionally, initializing the game board before starting is recommended for better program structure. Overall, addressing the loop condition and implementing these suggestions should resolve the quitting issue.
M.M.M
Messages
24
Reaction score
0
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:
Physics news on Phys.org
M.M.M said:
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"

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 textbook 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:
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 ?
 
M.M.M said:
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 ?

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
 
Thread 'Have I solved this structural engineering equation correctly?'
Hi all, I have a structural engineering book from 1979. I am trying to follow it as best as I can. I have come to a formula that calculates the rotations in radians at the rigid joint that requires an iterative procedure. This equation comes in the form of: $$ x_i = \frac {Q_ih_i + Q_{i+1}h_{i+1}}{4K} + \frac {C}{K}x_{i-1} + \frac {C}{K}x_{i+1} $$ Where: ## Q ## is the horizontal storey shear ## h ## is the storey height ## K = (6G_i + C_i + C_{i+1}) ## ## G = \frac {I_g}{h} ## ## C...
Back
Top