``````So; I have to determine if there is a) 3 of a kind b)4 of a kind c)straight.
I have put the 7 cards into a 1 dimensional array and sorted them but I also need a case for not being more than 4 cards. I don't need to include suits.
Here is what I have done:

include<iostream>
using namespace std;

include<cmath>
include<ctime>
include<cstdlib>
include<iomanip>
int main()
{
const int size=7;
int cards[size]={};
const int b=13;
int tem[b]={0};
int a; int p;
srand(time(0));
for(int i=0; i<10; i++)

{ for (int s=0; s<size; s++)
{ cards[s]=1+rand()%13; }
int i = 0, temp;
while( i < size ){
if ( i == 0 || cards[i - 1] <= cards[i] )
i++;
else{
temp =cards[i];
cards[i] = cards[i - 1];
cards[--i] = temp;}}

for (p=0; p<b; p++)
{tem[p-1]++;
if(tem[p]==3)
for (int m=0; m<size; m++)
cout<<setw(4)<<cards[p]; cout<<"Three of a kind. ";
cout<<endl;} }
system("pause");
return 0;
}

it does not work though
4 of a kind is about the same as 3 of a kind
no idea for the straight
``````
4
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by Lerner

in my opinion, you should write functions that evaluate everything from royal flush to high card:

``````//function prototypes
bool is_royal_fush(hand[7]);
bool is_straight_flush(hand[7]);
bool is_4kind(hand[7]);
bool is_full_house(hand[7]);
bool is_flush(hand[7]);
bool is_straight(hand[7]);
bool is_3kind(hand[7]);
bool is_2pair(hand[7]);
bool is_pair(hand[7);
int get_high_card(hand[7]);
``````

Some hands might qualify for several winning scenarios, so it is important to test from royal flush down to high card and break at the first true test in order to get the highest value of the hand.

I am just starting to learn c++ and the other tasks seem hard. I just need to evaluate 3 of a kind , four of a kind and straight. Anny opinion on how to?

Create a for loop that will evaluate each card in the hand using switch logic. For example:

``````int[] ThreeOfAKind = new int[3];

for (int i = 0; i < 3; i++) {
for (int x = 0; x < 7; x++) {
if (i >= 1)
ThreeOfAKind[i] = ThreeOfAKind[i - 1] + 1 == hand[i] ? hand[i] : 0;

else
ThreeOfAKind[i] = hand[i];
}
}

// or

for (int i = 0; i < 7; i++) {
switch (hand[i]) {
case 0: /* do something */ break;
}
}
``````

The first example would be a little buggy and needs tweaking but it's just pseudocode. You should read each card in the hand and determine if there are 3 in ascending order. Use a multi-dimensional array or something to read each. But as @Clinton Portis stated, you should build some functions to do your bidding for you. Create a card class, a deck class, and then in the main thread run all the game logic dealing with each.

``````for each card with index zero to 4  //control card A
for each card starting at the above index + 1 going to index 6  //control card B
if card A equals card B
increment counter
after the inner loop is finished if counter equals 3
you have 3 of a kind
``````

Change the numbers inside the for statements a little to check for 4 of a kind

For a straight, sort the cards by value. start at lowest value and see if each successive card has a value one higher than current card for however many cards you need to make a straight. If it's 5 cards to make a straight, then you need to look at just the first 3 as a possible low card in the straight.

``````for i == zero to 2 //control where to start
k = i
j = 0
while j < 4  //control how many comparisons to make
look at relationship between adjacent cards  //if not correct relationship
break  //stop looking for this i
else
move to next two cards
if j == 4  //check value of j after loop done
this is a straight
``````
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.