Thread: Fence Post ?

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    719

    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?
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    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.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    536
    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
    Last edited by Dave Evans; 03-27-2005 at 11:30 AM.

  4. #4
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    I see nothing wrong with the logic so far. What about CCard's constructors/destructor and set()?
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help (Trying to post message)
    By mrkm in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 10-06-2003, 04:05 PM
  2. Post your Best Text Adventure
    By Joe100 in forum Game Programming
    Replies: 3
    Last Post: 08-15-2003, 05:47 PM
  3. Auto POST
    By vasanth in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 06-07-2003, 10:42 AM
  4. post update
    By iain in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-12-2001, 10:47 AM