Question:
Updated Constructor, Still having trouble getting the values to be different.?
anonymous
2010-02-27 10:16:17 UTC
For my constuctor, I need 52 cards, just like a normal deck. However, I can only get the same card for all 52. When I shuffle the cards, the value and suit change, but again all 52 are the same thing. I tried to implement the suggestions from last time, but I still unable to get everything to work properly. I believe my setSuit and setValue functions are not being set properly in the cardArray. The suit types are enums, where spades =1, clubs=2, heart=3, diamonds=4. SUITS and VALUES are constant global variables where SUIT=4, VALUE=13.
My code is...
card ocd; //card obeject that's used to call the card member functions
deck :: deck () //constructor for my deck class
{
for (int i=0;i {
if (i == 0)
ocd.setSuit(SPADE); //function call to the card member function and enum type
else if (i == 1)
ocd.setSuit(CLUB);
else if (i == 2)
ocd.setSuit(HEART);
else if (i == 3)
ocd.setSuit(DIAMOND);
for (int j=0; j {
ocd.setValue(j+1); //function call to the member function in card class, starts at j+1 because the values for the card start at one
//sets the cardArray private deck member to the card object
cardArray [i][j] = ocd;

}
}
}
Thank you for any help and suggestions.
Four answers:
Mark aka jack573
2010-03-02 20:19:36 UTC
From what I can read from this question alone. I have not looked at your other questions, I would say it has to do with the way you are seeding the random number generator.



You should do this to seed the random number generator so you will have better random numbers.



srand(time(0)); // seed random number generator



It appears that you are always using the same number to seed it, so it will produce the same sequence of numbers.



You need the time.h file included for the time function.



Good luck.
KaliMan
2010-02-27 11:21:45 UTC
I really need to see the rest of your code, but one thing jumps out at me a bit. It is not clear to me why your deck is a two dimensional array. The way it is now, cardArray[SPADE,1] is set to the ace of spades. Well, I can tell that just by looking at the subscripts. When ever you have redundant information like that you risk them getting out of sync. It also makes the concept of shuffling the two dimensional array deck a bit strange.



But anyways, like I said, I would really need to see the other code - do you still have my email address?
roher
2017-01-15 13:37:47 UTC
I truthfully have this issue all the time. only because of the fact I placed on a bunny in superb condition does no longer advise i'm honest pastime interior the place of work. heavily. And as quickly as I capture them commencing at my tail they turn around and act like i'm the obsessed one. I accept as true with you. only tell them to ask you out like popular people. i admire my dad too.
jimbot
2010-02-27 10:27:06 UTC
To me it sounds like your shuffle function isn't working, but since your QA network is private I can't go and look at your previous question.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...