Solving C Program Problem: X/O Game Quitting Unexpectedly

  • Thread starter Thread starter M.M.M
  • Start date Start date
  • Tags Tags
    Program
Click For Summary

Discussion Overview

The discussion revolves around a programming issue related to a C program designed to implement the X/O game (Tic-Tac-Toe). Participants are exploring the reasons why the program unexpectedly quits during execution, focusing on loop conditions and game logic.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant reports that their X/O game program quits unexpectedly and seeks help to identify the issue.
  • Another participant suggests that the loop termination condition may be incorrect, potentially causing the program to terminate after the first move.
  • One participant mentions that they check for winning conditions after every play but acknowledges that the while loop condition might be problematic.
  • A suggestion is made to count the moves to help diagnose the loop condition's behavior.
  • It is advised to initialize the game board before starting, although this may not be strictly necessary in C++.

Areas of Agreement / Disagreement

Participants express differing views on the specific cause of the program's termination, with some focusing on the loop condition and others on the initialization of the game board. The discussion remains unresolved as no consensus is reached on the exact solution.

Contextual Notes

There are indications of missing assumptions regarding the loop conditions and the initialization of the game board, which may affect the program's behavior. The discussion does not clarify the exact nature of these assumptions.

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
 

Similar threads

Replies
1
Views
4K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
10
Views
2K
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K