OK then. But since you still need the magic 52 in many places, having a static const that represents the size of the whole deck wouldn't hurt.I am going to use this code for a console based BlackJack game, and i am using the DeckSize variable to keep track of how many cards are left in the deck after i draw the top one, that is also why i didn't declare it as a constant.
I meant you can use it as a local variable where you need it. But don't make it a data member of the class. When you hold a real deck of cards in your hand, do you somehow feel that Seconds is a part of it?...About the time_t variable: The code i used is just something i basically copied from the FAQ on this site, i figured there would be nothing wrong with it then. I'll make sure i get rid of it though.
I might be wrong.
Quoted more than 1000 times (I hope).Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
Do you really think the size of a deck of cards is going to change? If it's standard Blackjack, how could it ever be played except with a standard deck?
I hardly think that 52 is a "magic" number in a program which plays a card game. Making it a macro or constant might imply that it could be changed to some other value.
But you can easily make a typo and have an array of size 5 that the compiler never catches. Its not a big deal but I would probably use the constant not the literal.
>> Daved may be referring to the fact that if (i + 1) in above statement is not a factor of RAND_MAX, the results tend to be biased but I don't think it would make that much difference here.
No, I wasn't referring to that. I agree that such an issue is not important for a toy application. I was referring to potential for something like the 3,4,5 thing mentioned, and basically saying what you said, the index calculation is way too complicated.
However, if you did want to make a real game that people play and make or bet real money with, then you would of course have to use a totally different and much more advanced random number generation scheme. There was an online poker site many years ago that tried to write a random shuffling algorithm like this that they thought was correct. Turns out it had tons of flaws and some guys were able to write a program that knew everybody's cards as they were playing.
"Do you really think the amount of memory we'll need is ever going to be greater than 640KB...?"
One of the wonderful things about change, is that its so often unpredictable
by the way, have you never played a game which uses the Jokers? That would make your deck a size of 54..
Besides, even if it were a number which couldn't change (such as PI, or Gravity on planet earth) as others have mentioned, leaving literals lying around your code is undesirable.
.. Another good example is NULL, which is always 0, however, when defining a null pointer, which one would you use..?
>> Another good example is NULL, which is always 0, however, when defining a null pointer, which one would you use..?
0
http://www.research.att.com/~bs/bs_faq2.html#null
Just curious, when would you use (void*)0 or is that equivalent to 0? I did some googling but only found more confliciting discussions. Could someone explain the differences if any?
"Knowledge is proud that she knows so much; Wisdom is humble that she knows no more."
-- Cowper
Operating Systems=Slackware Linux 9.1,Windows 98/Xp
Compilers=gcc 3.2.3, Visual C++ 6.0, DevC++(Mingw)
You may teach a person from now until doom's day, but that person will only know what he learns himself.
Now I know what doesn't work.
A problem is understood by solving it, not by pondering it.
For a bit of humor check out xkcd web comic http://xkcd.com/235/
>> when would you use (void*)0 or is that equivalent to 0?
In C?