# Fence Post ?

• 03-27-2005
misplaced
Fence Post ?
i'm missing the first element in the vector, and have an extra one on the end which has a bad value in it. more precisly, the ace of hearts should be deck[0]. but it's not. the 2 of hearts is deck[0].
it goes thru fine up thru the hearts, then the clubs, then the spades...then, at the very end, i get the 0 (zero) of hearts. i know that the error HAS to be here..

Code:

```void CDeck::createDeck(void) {     clearDeck();              //clearDeck(void){ deck.clear(); }     CCard c;         for(int i = 0; i < 4; i++)          //for each suit.....         for(int j = 0; j < 13; j++)    //create 13 cards         {                 c.set(j+1,j+1,i);        //param 1 = rank, param 2 = value , param 3 = suit                 deck.push_back(c); //deck is of type vector<CCard>                                                 //declared in the class header                         }      }```
but i just can't find it.

anyone?
• 03-27-2005
Magos
Quote:

param 2 = value
j+1
That would give the number 1 to 13, not 0 to 12. I don't know how you interpretate these values, but it might be your problem.
• 03-27-2005
Dave Evans
Quote:

Originally Posted by misplaced
i know that the error HAS to be here..

but i just can't find it.

anyone?

Let's see:

I'm not so sure that the error HAS to be here.

Here's a way to see what's really happening:

In this function:

After clearDeck(), print out the size of the vector (should be zero, obviously).

After your loop, print out the size of the vector (should be 52, obviously)

Print out the rank, value and suit of deck[0] (1, 1, 0: right?)
Print out the rank, value and suit of deck[51] (13, 13, 3: right?)

If these values all check, then the error is somewhere else. If these values don't check, then show some more context so you (and we) have some chance of getting to the bottom of things.

Regards,

Dave
• 03-27-2005
Hunter2
I see nothing wrong with the logic so far. What about CCard's constructors/destructor and set()?