string vectors

I have two vectors, one is full of numbers and the other with suits (a deck of cards if they are put together). After I print out the first five elements of each (a "hand"), I need to determine if that "hand" contains 2 of a kind. I am so stumped on how to do this! what I have so far is below:


#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>

using namespace std;

void fillvector(vector<string> &N, vector<string> &S);
void shuffledeck(vector<string> &N, vector<string> &S);
void printdeck(int i, vector<string> &N, vector<string> &S);
void printfive(int i, vector<string> &N, vector<string> &S);
void evaluatehand(int pos, int i, int pair, vector<string> &N, vector<string> &S);

int main(int argc, char *argv[])
{
vector<string> N, S;

srand ( unsigned ( time (NULL) ) );
int i = 0;
int pos;
int pair = 0;
fillvector(N, S);
shuffledeck(N, S);
printdeck(i, N, S);
printfive(i, N, S);
evaluatehand(pos, i, pair, N, S);


system("PAUSE");
return EXIT_SUCCESS;
}

void fillvector(vector<string> &N, vector<string> &S)
{
//Aces are high (14)

N.insert(N.end(), 4, "2" );
N.insert(N.end(), 4, "3" );
N.insert(N.end(), 4, "4" );
N.insert(N.end(), 4, "5" );
N.insert(N.end(), 4, "6" );
N.insert(N.end(), 4, "7" );
N.insert(N.end(), 4, "8" );
N.insert(N.end(), 4, "9" );
N.insert(N.end(), 4, "10" );
N.insert(N.end(), 4, "11" );
N.insert(N.end(), 4, "12" );
N.insert(N.end(), 4, "13" );
N.insert(N.end(), 4, "14" );
S.insert(S.end(), 13, "C" );
S.insert(S.end(), 13, "H" );
S.insert(S.end(), 13, "D" );
S.insert(S.end(), 13, "S" );




}

void shuffledeck(vector<string> &N, vector<string> &S)
{
random_shuffle( S.begin(), S.end() );
random_shuffle( N.begin(), N.end() );

}

void printdeck(int i, vector<string> &N, vector<string> &S)
{
for(i=0; i < 3 ; ++i)
{
cout << setw(4)<< N[i] << S[i] << " ";

}
cout << endl;
for(i=3; i < 6 ; ++i)
{
cout << setw(4)<< N[i] << S[i] << " ";

}
cout << endl;
for(i=6; i < 9 ; ++i)
{
cout << setw(4)<< N[i] << S[i] << " ";

}
cout << endl;
for(i=9; i < 12 ; ++i)
{
cout << setw(4)<< N[i] << S[i] << " ";

}
cout << endl;
for(i=12; i < 15 ; ++i)
{
cout << setw(4)<< N[i] << S[i] << " ";

}
cout << endl;
for(i=15; i < 18 ; ++i)
{
cout << setw(4)<< N[i] << S[i] << " ";

}
cout << endl;
for(i=18; i < 21 ; ++i)
{
cout << setw(4)<< N[i] << S[i] << " ";

}
cout << endl;
for(i=21; i < 24 ; ++i)
{
cout << setw(4)<< N[i] << S[i] << " ";

}
cout << endl;
for(i=24; i < 27 ; ++i)
{
cout << setw(4)<< N[i] << S[i] << " ";

}
cout << endl;
for(i=27; i < 30 ; ++i)
{
cout << setw(4)<< N[i] << S[i] << " ";

}
cout << endl;
for(i=30; i < 33 ; ++i)
{
cout << setw(4)<< N[i] << S[i] << " ";

}
cout << endl;
for(i=33; i < 36 ; ++i)
{
cout << setw(4)<< N[i] << S[i] << " ";

}
cout << endl;
for(i=36; i < 39 ; ++i)
{
cout << setw(4)<< N[i] << S[i] << " ";

}
cout << endl;
for(i=39; i < 42 ; ++i)
{
cout << setw(4)<< N[i] << S[i] << " ";

}
cout << endl;
for(i=42; i < 45 ; ++i)
{
cout << setw(4)<< N[i] << S[i] << " ";

}
cout << endl;
for(i=45; i < 48 ; ++i)
{
cout << setw(4)<< N[i] << S[i] << " ";

}
cout << endl;
for(i=48; i < 51 ; ++i)
{
cout << setw(4)<< N[i] << S[i] << " ";

}
cout << endl;
for(i=51; i < 52 ; ++i)
{
cout << setw(4)<< N[i] << S[i] << " ";

}
cout << endl;
}

void printfive(int i, vector<string> &N, vector<string> &S)
{
cout << "The hand you have been dealt is: ";
for(i= 0 ; i < 5; i++ )
{
cout << N[i]<< S[i] << " ";
}
cout << endl;
}

void evaluatehand(int pos, int i, int pair, vector<string> &N, vector<string> &S)
{
for (i = 0; i < 5 ; i++)
{
pos=N.search("2", 0);
if(pos != string::npos)
{
if( pos < 5)
{
pair++;
if (pair == 2)
{
cout << "You drew a pair of twos!" << endl;
}

}
}

}
}
See your thread on the inventory vector for my answer.
Topic archived. No new replies allowed.