card shuffling dealing question

This is a discussion on card shuffling dealing question within the C++ Programming forums, part of the General Programming Boards category; Ok the problem is to have a typical card shuffling and dealing program but to also display the color of ...

  1. #1
    Unregistered
    Guest

    Exclamation card shuffling dealing question

    Ok the problem is to have a typical card shuffling and dealing program but to also display the color of each dealt card and to indicate a face card with an asterick.

    Most of the program is done but I am having a few problems- mainly after declaring a boolean variable (isFace) and assigning true to the variable if the card is a face card and false if it isn't.

    I think its simple but it just isn't clicking with me. Any suggestions will be appreciated.

    I know I need to use strcmp but I don't understand what I'm comparing. I'm not asking for people to do my work- just helpful hints and suggestions

    Thanks,

    Code:
    #include <iostream>
    
    using std::cout;
    using std::endl;
    using std::ios;
    
    #include <iomanip>
    
    using std::setiosflags;
    using std::setw;
    
    #include <cstring>
    
    #include <ctime>
    
    #include <cstdlib>
    
    void deal( const int [][ 13 ], const char *[], 
               const char *[], const char *[] );
    void shuffle( int [][ 13 ] );
    
    int main()
    {
       const char *suit[ 4 ] =  
          { "Hearts", "Clubs", "Diamonds", "Spades" };
       const char *face[ 13 ] = 
          { "Ace", "Deuce", "Three", "Four",
            "Five", "Six", "Seven", "Eight",
            "Nine", "Ten", "Jack", "Queen", "King" };
       const char *color[2] = { "Red", "Black"};
    
       int deck[ 4 ][ 13 ] = { 0 };
    
       shuffle( deck );
       deal( deck, face, suit, color );
    
       return 0;
    }
    
    void deal( const int wDeck[][ 13 ], const char *wFace[],
               const char *wSuit[], const char *wColor[] )
    {
       for ( int card = 1; card <= 52; card++ )
    
          for ( int row = 0; row <= 3; row++ )
    
             for ( int column = 0; column <= 12; column++ )
    
                if ( wDeck[ row ][ column ] == card )
                {
    
    	bool isFace;
    
    
                   HERES MY PROBLEM
    
                   /* write statement to determine if the current
                      card is a face card. If it is, assign true
                      to variable isFace. If it is not, assign
                      false to variable isFace */
    
                   cout << setw( 5 ) << setiosflags( ios::right )
                        << wFace[ column ] << " of "
                        << setw( 8 ) << setiosflags( ios::left )
                        << wSuit[ row ] << "  ";
                  cout << wColor[column] << endl;
    
                   /* Write statement to display an asterick
                      if it is necessary */
    
                   cout << ( card % 2 == 0 ? '\n' : '\t' );
                }
    }
    
    void shuffle( int wDeck[][ 13 ] )
    {
       int row, column;
    
       srand( time( 0 ) );
    
       for ( int card = 1; card <= 52; card++ ) {
          do {
             row = rand() % 4;
             column = rand() % 13;
          } while( wDeck[ row ][ column ] != 0 );
    
          wDeck[ row ][ column ] = card;
       }
    }

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    162
    I think I get what you are trying to do. Just see if row in wSuit is >= 9, Jack through a King. It shouldn't be much harder than that.

  3. #3
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    Look into the algorithm header because there is a function in there that you would love, its called random_shuffle. heres its prototype:
    Code:
    template<class RanIt>
        void random_shuffle(RanIt first, RanIt last);
    i believe this works with standard containers using iterators, id say random iterators from the look of the RanIt in the template.
    Last edited by xds4lx; 04-03-2002 at 11:45 PM.
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Rolodex(information manager) =>Check my Code
    By jackfraust in forum C++ Programming
    Replies: 3
    Last Post: 04-26-2009, 04:41 AM
  2. newbie question dealing with an error
    By zack787 in forum C Programming
    Replies: 2
    Last Post: 02-27-2008, 04:49 PM
  3. How can I access a struct (from a header file)?
    By loxslay in forum C++ Programming
    Replies: 3
    Last Post: 10-07-2006, 02:25 PM
  4. Problem With My Box
    By HaVoX in forum Tech Board
    Replies: 9
    Last Post: 10-15-2005, 08:38 AM
  5. graphics card question
    By dP munky in forum Tech Board
    Replies: 4
    Last Post: 01-09-2003, 09:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21