Solving C Program Problem: X/O Game Quitting Unexpectedly

  • Thread starter M.M.M
  • Start date
  • Tags
    Program
In summary, the problem is with the termination condition of the while loop. You could try changing it or trying some other solutions.
  • #1
M.M.M
24
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
  • #2
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:
  • #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 ?
 
  • #4
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
 

Related to Solving C Program Problem: X/O Game Quitting Unexpectedly

1. What could be causing the X/O game to quit unexpectedly?

There could be several reasons for the game quitting unexpectedly, such as a logical error in the code, a memory leak, or an issue with the user input.

2. How can I troubleshoot the issue with the X/O game quitting unexpectedly?

You can start by reviewing your code and checking for any errors or bugs. You can also use a debugger to track the program's execution and identify any issues. Additionally, checking the program's memory usage can help identify potential memory leaks.

3. Can the problem be related to the computer's hardware or operating system?

It is possible that the issue is caused by the computer's hardware or operating system, especially if the game works fine on other devices. In this case, updating the drivers and software or running the game on a different computer can help troubleshoot the issue.

4. How can I prevent the X/O game from quitting unexpectedly in the future?

You can prevent the game from quitting unexpectedly by thoroughly testing your code, handling errors and exceptions, and properly managing memory usage. It is also helpful to gather feedback from users and make any necessary improvements to the game's functionality.

5. Are there any common mistakes that could be causing the X/O game to quit unexpectedly?

Some common mistakes that can cause the game to quit unexpectedly include not properly closing files, not handling input validation, and not freeing allocated memory. It is important to double-check your code and ensure that all possible scenarios are accounted for.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
5
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
Replies
10
Views
975
  • Programming and Computer Science
Replies
4
Views
1K
  • Atomic and Condensed Matter
Replies
4
Views
2K
Replies
2
Views
2K
  • Programming and Computer Science
Replies
2
Views
2K
  • Programming and Computer Science
Replies
2
Views
1K
Back
Top