Why does the program keep going, when I tell it to stop?

Go To StackoverFlow.com

0

I'm struggling to create a little Blackjack console game in C++. I've written almost the whole code (you may find it pretty messy, but I have like no experience in this kind of things). It works, but not completely. As you know (or no) when your cards' value equals 21 you win the game, and if you have more - you lose. In my project the game never stops, When you get 21, when dealer gets 21 or when you pass 21, the game is still on. Maybe I forgot to add something and I'd be really pleased if you could point it out! :) CODE

2012-04-05 17:22
by Maciej Zwierzchlewski
This is exactly the kind of error that debuggers are great for. Step through your program and see what happens for yourself - suszterpatt 2012-04-05 17:24
And learning to use the debugger this way will serve you very well in the future - Almo 2012-04-05 17:25
Having trouble getting your code. If it's too big to post here, it's probably too big - Beta 2012-04-05 17:27


3

In your main() function, you are defining a new local state variable:

GAMESTATE GSState = GAME;

that shadows the global one that your other classes are updating to indicate the end of the game.

You should have only assigned it a value:

GSState = GAME;

With gcc, you can compile with the flag -Wshadow if you want the compiler to warn you about this kind of potential errors (but there might be a lot of false positive).

2012-04-05 17:35
by alexisdm
Thank you sir, I owe you one! : - Maciej Zwierzchlewski 2012-04-05 17:38
Ads