Ok, I have a deck of 52 cards stored in a vector named V of strings as V[?]=2D for 2 of Diamonds and V[?]=14S for ace of spades, etc... They have been shuffled so they are not in the correct order. I have printed the first 5 cards to be considered a "hand". I need to determine whether or not that hand contains a pair, 2pair, 3ofaKind, 4ofaKind, FullHouse, Flush or Straight. To me, this is much more complicated than usual since the elements contain not only the number but ALSO a letter which indicates the suit. any suggestions? THANK YOU!!
void fillvector(int i, vector<string> &V);
void shuffledeck(vector<string> &V);
void printdeck(int i, vector<string> &V);
void printfive(int i, vector<string> &V);
void evaluatehand(int pos, int i, vector<string> &V);
int main(int argc, char *argv[])
{
vector<string> V;
srand ( unsigned ( time (NULL) ) );
int i;
int pos;
fillvector(i, V);
shuffledeck(V);
printdeck(i, V);
printfive(i, V);
evaluatehand(pos, i, V);
void printfive(int i, vector<string> &V)
{
cout << "The hand you have been dealt is: ";
for(i= 0 ; i < 5; i++ )
{
cout << V[i] << " ";
}
cout << endl;
}
void evaluatehand(int pos, int i, vector<string> &V)
{
Please use [code][/code] tags.
Here is a trick on how to get the value and suit of your cards:
1 2 3 4 5 6
// you need to #include <sstream>
string card = "11S";
stringstream ss ( card ); // create a stream with the contents of the card
int value;
char suit;
ss >> value >> suit; // read the stream into the variables
After doing that you can pass the results to some functions for comparison.
BTW V.push_back ( "14D" ); does the same as V.insert(V.end(), 1, "14D" ); with less typing
Personally I would create a Card struct that has two elements which separate out the face value from the suit, since in all of your programming except display to the user you will want to separate them.
ok, so I can use multidimensional vectors for this right? Would it work if I made the rows the numbers and the column the suit? I have never used multidimensional anything before but if that's how I need to do it... So I declared my vector as such:
vector< vector<string> > V;
will this method work? So how would I assign the suits and numbers to this 2D vector? If I say:
V[0][0]= {{"2"}, {"S"}}
will it assign the number 2 to the row and S to the column? And then when I say: