.

There was a video we had to follow, but the arrays didn't match cause I changed them, but didn't put two and two together
Last edited on
Inside a function, the following variables exist:

1) Variables passed to that function as parameters.
2) Variables created in that function.
3) Variables that exist everywhere.

ans, boardNum, ansBoard

Were these variables passed to main as parameters? No
Were these variables created inside main? No
Do these variables exist everywhere? No

So do these variables exist inside main?


it looks like the problem here is that you don't understand how to call a function. That's very fundamental; you need to go back and learn that first.
Last edited on
A) It seems you use NULL to assign ‘0’ to int variables. Since NULL is commonly defined as 0, that apparently works. Anyway, you shouldn’t do that: do use 0!

1) NULL was created to explicitly tell: «This pointer is not pointing to an available memory area» - it shouldn’t be used for different purposes.

2) In C++ NULL has been replaced by nullptr - do use nullptr (but only with pointers!).

3) NULL could betray you:
https://channel9.msdn.com/Shows/Going+Deep/Stephan-T-Lavavej-Everything-you-ever-wanted-to-know-about-nullptr
(from minute 16 on - please note that’s a long, technical video)


B) Line 77: (3 - 1 + 1)
I’m not good at math, but I think 3 - 1 + 1 == 3


C) Before using std::rand() you should initialize std::srand()!


D) After this instruction
int usedBoards[3] = { NULL };
all cells inside usedBoards should be initialized to 0. So, in beginGame(), the if condition is always true:
if (playedBoard[r] == 0) return r;


E) If you generate numbers randomly, why do you define three tables of numbers?
Codes share a weird tendency to periodically come back on this forum:
http://www.cplusplus.com/forum/beginner/235104/
Enoizat, that's hilarious. I thought I remembered seeing something before where the OP put NULL as an element in an int array..
Codes share a weird tendency to periodically come back on this forum

Code reuse can be taken to ridiculous extremes, especially when it is the same defective code to begin with.
Enoizat wrote:
Codes share a weird tendency to periodically come back on this forum:


That is something a troll would probably do. It happened quite a lot with obscure code from other sites posted here too.
Topic archived. No new replies allowed.