Program doesnt go in a loop

I have been trying to learn how to make simple games on c++ like snake. I was able to make a complete snake game. It was flickering a lot because i was clearing the screen and drawing all the map over and over again. And right now i wrote a similar code to make another game but it just doesnt go into loop of clearing the screen and drawing all again. How can i make the program go forever ? I can only share the main function and here it is:

int main()
{
srand(time(0));
Setup();

while (gameover == false){

srand(time(0));
Draw();
Input();
Logic();
}

if(gameover == true){
system("cls");
if(RightScore > LeftScore)
cout << "\n\n\n\n\n\n\n" << " RIGHT SIDE WINS" << "\n\n\n\n\n";
else
cout << "\n\n\n\n\n\n\n" << " LEFT SIDE WINS" << "\n\n\n\n\n";

}
return 0;
}
Last edited on
You don't show where gameover is initialized (if it is at all). It could be garbage (non-zero), in which case your loop won't execute at all.

BTW, if (gameover == true) is not necessary. The only way you can exit the loop above it is if gameover is true.

PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.

Do not call srand() multiple times. srand() sets the RNG to a particular starting point. Calling srand() repeatedly can cause rand() to return the same random numbers. srand() should be called ONCE at the beginning of main().
http://www.cplusplus.com/reference/cstdlib/srand/
Topic archived. No new replies allowed.