I'm completely new to C++, and my teacher gave us a card game to do for our first assignment. The card game has to deal a hand of five cards and determine whether or not it contains a flush, a pair, a straight, three of a kind, or four of a kind. I think I got it to deal the hand right, but I am completely lost on how to do the other methods. Could somebody please give me a hint as to how to start the methods? I'm not asking anyone to do my homework. I just need help with starting one of the methods. I think that if somebody helped me with one, I could do the rest. Any help would be greatly appreciated, because I am panicking! Thanks in advance!

// Member-function definitions for class DeckOfCards that simulates
// the shuffling and dealing of a deck of playing cards.
#include <iostream>
using std::cout;
using std::left;
using std::right;
#include <iomanip>
using std::setw;
#include <cstdlib> // prototypes for rand and srand
using std::rand;
using std::srand;
#include <ctime> // prototype for time
using std::time;
#include "DeckOfCards.h" // DeckOfCards class definition
// DeckOfCards default constructor initializes deck
DeckOfCards::DeckOfCards()
{
   // loop through rows of deck
   for ( int row = 0; row <= 3; row++ )
   {
      // loop through columns of deck for current row
      for ( int column = 0; column <= 12; column++ )
      {
         deck[ row ][ column ] = 0; // initialize slot of deck to 0
      } // end inner for
   } // end outer for
   
   srand( time( 0 ) ); // seed random number generator
} // end DeckOfCards default constructor
// shuffle cards in deck
void DeckOfCards::shuffle()
{
   int row; // represents suit value of card
   int column; // represents face value of card
   // for each of the 52 cards, choose a slot of the deck randomly
   for ( int card = 1; card <= 52; card++ ) 
   {
      do // choose a new random location until unoccupied slot is found
      {
         row = rand() % 4; // randomly select the row
         column = rand() % 13; // randomly select the column
      } while( deck[ row ][ column ] != 0 ); // end do...while
      // place card number in chosen slot of deck
      deck[ row ][ column ] = card;
   } // end for
} // end function shuffle
void DeckOfCards::deal()
{
   // initialize suit array
   static const char *suit[ 4 ] = 
      { "Hearts", "Diamonds", "Clubs", "Spades" };
   // initialize face array
   static const char *face[ 13 ] = 
      { "Ace", "Deuce", "Three", "Four", "Five", "Six", "Seven", 
      "Eight", "Nine", "Ten", "Jack", "Queen", "King" };
   // for each of the 5 cards
   for ( int card = 1; card <= 5; card++ )
   {
      // loop through rows of deck
      for ( int row = 0; row <= 3; row++ )
      {
         // loop through columns of deck for current row
         for ( int column = 0; column <= 12; column++ )
         {
            // if slot contains current card, display card
            if ( deck[ row ][ column ] == card ) 
            {
               cout << setw( 5 ) << right << face[ column ] 
                  << " of " << setw( 8 ) << left << suit[ row ]
                  << ( card % 2 == 0 ? '\n' : '\t' );
            } // end if
         } // end innermost for
      } // end inner for
   } // end outer for
} // end function deal
'Stein commented: Heh no worries about Narue, buddy. Keep workin. ;) -'Stein +3

>I'm completely new to C++, and my teacher gave us a card game to do for our first assignment.
One of these statements is a lie.

commented: spreading rep - Salem +3

>I'm completely new to C++, and my teacher gave us a card game to do for our first assignment.
One of these statements is a lie.

Huh? I'm not lying! Neither of those statements was a lie. I'm new to C++, and I'm completely lost.

>I'm not lying!
Sure you are. Are you trying to convince us that some school actually gave a complete beginner code and logic that would typically be reserved for second or third semester programming courses? Your post shows all the signs of a slacker who's suddenly facing a failing grade for his laziness.

We'll still help, but you're going to need to do more than just show us code that your teacher probably gave and in a lame attempt to appear as if you're doing work.

>I'm not lying!
Sure you are. Are you trying to convince us that some school actually gave a complete beginner code and logic that would typically be reserved for second or third semester programming courses? Your post shows all the signs of a slacker who's suddenly facing a failing grade for his laziness.

We'll still help, but you're going to need to do more work than just show us code that your teacher probably gave and in a lame attempt to appear as if you're doing work.

Well, apparently you've never heard of my school. Honestly, I am not lying. I have taken several Java classes, but I have never taken a C class. I have an hour long C++ class once a week. My class has met 3 times, and my teacher gave us this to do. I do not know C, so I have no idea where to start. I'm not looking for someone to do my homework for me. I just need a hint on where to start.

>Well, apparently you've never heard of my school.
Apparently every school on the planet is incompetent, because your "problem" seems to be the norm. :rolleyes:

>I'm not looking for someone to do my homework for me. I just need a hint on where to start.
If I were you, I would take some of the knowledge obtained from my Java courses and apply them to C. The meat of programming is language independent, so you really can't use the "I know Java but not C or C++" excuse.

First, you need to understand the problem. Then you need to work out the steps for solving the problem, preferably on paper and completely by hand. Even a "complete beginner" such as yourself should have little trouble working out the basic steps in an unfamiliar language with a complete understanding of how the solution should work.

When you have a specific problem (ie. something besides "I don't know where to start"), I'll be in a better position to help you.

I appreciate your help. I honestly am new to C++. Ok...my first problem is with the deal method. I changed the deal method. It originally printed out all 52 cards in the deck. I'm not sure if what I did (change the method to print out 5 cards) is right. I'm also confused with how to access the array for each method. I know that I need to call the array of 5 cards and use a loop to check for duplicates.

I have not looked into your code (I'm to lazy) and I can't poker either. I think you can do it by making an buffer array (where you store the cards in) of 4 elements and an second boolean array to of 4 elements

int buffer[4]; bool array[4];

Find out what combination of cards you need for an flash, let's say that that is card 1,2,3 and 4. I store those in my second array.

array[0] = 1;
array[1] = 2;
array[3] = 3;
array[4] = 4;

then make an function to check wether the entered card (in the function) exists in the array array.

bool checker(int card)
{
    for(int a = 0; a < 4; a++)
        if(card == array[a]){array[a] = 0; return true;}
    return false;
}

then just check your buffer array

for(int a = 0; a < 4; a++)
{
     if(!checker(buffer[a]))
         //not a flush
}

Hope I didn't gave away to much but I really suck at giving hints :/
I didn't tested this code, it's up to you to debug it. I hope you get what I'm trying to explain.

Thank you so much for your help! That definitely gives me a start!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.