### snake game

I'm working through a youtube tutorial on making a snake game and have came accross an error I can't seem to solve.

when 0 passes over 'F' a new 'F' should spawn at a different random location. My code seems to be the same as the video(There's is working).

any help is appriciated.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128`` `````` #include #include #include #include #include using namespace std; bool gameOver; const int width = 20; const int height = 20; int x,y, fruitX, fruitY, score; enum eDirection { STOP = 0, LEFT, RIGHT, UP, DOWN}; eDirection dir; void setup() { gameOver = false; dir = STOP; x = width / 2; y = height / 2; fruitX = rand()% width; fruitY = rand()% height; score = 0; } void Draw() { system("cls"); for (int i=0; i < width +2; i++) cout<<"#"; cout<width || x<0 || y>height || y<0) gameOver= true; if(x==fruitX && y==fruitY) { score +=10; fruitX = rand()% width; fruitY = rand()% height; } } int main() { setup(); while (!gameOver) { Draw(); Input(); Logic(); Sleep(50); } return 0; } ``````
One problem i see is at line 43 if (i == fruitX && j == fruitY)
i represents row and fruitX the column.
Using more meaningful names can prevent this kind of problem.

Another problem is that you don't seed the random generator - best place would be setup.