c++ tic tac toe | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

c++ tic tac toe

The game crashes when the computer chooses a played position. https://code.sololearn.com/cv0HpuQki8lq/#cpp

29th Jan 2018, 10:29 PM
linus_md
linus_md - avatar
2 Answers
+ 6
That's because you always pick the same spot so it runs until memory is gone. Your srand(time(NULL)) line should be in main so it is called only once. Each time you call it, it restarts the random number sequence. Since the current time doesn't change for a whole second, you end up passing the same number most times, getting the same sequence. Next time, link your code.
29th Jan 2018, 9:08 PM
John Wells
John Wells - avatar
+ 4
for big if(i == value) like that, use switch cases (works only for integer-like types) Instead of storing A, B, C, ... strings, store an array of string. With that, you can also change the switch with simply one if
29th Jan 2018, 10:08 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar