Hello everyone! I am currently working on creating a Poker Simulation using the language C++. However, I am having issues with my swap function and also creating the conditions, such as declaring a Flush or Pair. Here is the code I have so far, and if you can assist me with that that would be great.

#include <iomanip>
#include <iostream>
using namespace std;
void getCard(int);
void shuffle(int[]);
void swapHand(int[]);
int position = 0;
int deck[52];

int main()

{
	srand( unsigned(time(0)));
	int hand[5];
	int cardNumber;
	char arr[100];

	shuffle(deck);

	for(int i=0; i<52; i++)
		getCard(deck[i]);

	for(int i=0; i<5; i++)
	{
		hand[i] = deck[position++];
	}

	cout << "\n" << "Welcome to Kim's WissPoker!" << "\n" << endl;
	cout << "YOUR HAND:" << endl;
	for(int i=0; i<5; i++)
		getCard(hand[i]);

	cout << "\n"<< "Which card(s) would you like to reject? (1-5)" << endl;
	cin >> hand[cardNumber];
	swapHand([cardNumber]);

	bool running = true;
	while (running)
	{
	cout << "Would you like to reject another card? (Y or N)" << endl;
	cin.getline(arr,100);
	if (arr[0] == 'n' || arr[0]=='N')
			running = false;
	}

	
cout << "\n";	
system ("pause");
return 0;
}

void shuffle(int arr[])
{
	int range = 52;
	int startingPoint = 0;
	arr[0] = ( rand() % range ) + startingPoint;
	for(int i = 1; i < 52; i++)
	{
		arr[i] = ( rand () % range ) + startingPoint;
		for(int shuffle = i-1; shuffle >= 0; shuffle--)
		{
			if(arr[i] == arr[shuffle])
				i--;
		}
	}
}

void getCard(int randNum) {
	switch(randNum)
    {
        case 1:
            cout << "2 of Clubs" << endl;
        break;
       
        case 2:
            cout << "3 of Clubs" << endl;
        break;
       
        case 3:
            cout << "4 of Clubs" << endl;
        break;
       
        case 4:
            cout << "5 of Clubs" << endl;
        break;
       
		case 5:
			cout << "6 of Clubs" << endl;
		break;

		case 6:
			cout << "7 of Clubs" << endl;
		break;

		case 7:
			cout << "8 of Clubs" << endl;
		break;

		case 8:
			cout << "9 of Clubs" << endl;
		break;
		
		case 9:
			cout << "10 of Clubs" << endl;
		break;

		case 10:
			cout << "Jack of Clubs" << endl;
		break;

		case 11:
			cout << "Queen of Clubs" << endl;
		break;

		case 12:
			cout << "King of Clubs" << endl;
		break;

		case 13:
			cout << "Ace of Clubs" << endl;
		break;

		case 14:
			cout << "2 of Spades" << endl;
		break;

		case 15:
			cout << "3 of Spades" << endl;
		break;

		case 16:
			cout << "4 of Spades" << endl;
		break;

		case 17:
			cout << "5 of Spades" << endl;
		break;

		case 18:
			cout << "6 of Spades" << endl;
		break;

		case 19:
			cout << "7 of Spades" << endl;
		break;

		case 20:
			cout << "8 of Spades" << endl;
		break;

		case 21:
			cout << "9 of Spades" << endl;
		break;

		case 22:
			cout << "10 of Spades" << endl;
		break;

		case 23:
			cout << "Jack of Spades" << endl;
		break;

		case 24:
			cout << "Queen of Spades" << endl;
		break;

		case 25:
			cout << "King of Spades" << endl;
		break;

		case 26:
			cout << "Ace of Spades" << endl;
		break;

		case 27:
			cout << "2 of Diamonds" << endl;
		break;
		
		case 28:
			cout << "3 of Diamonds" << endl;
		break;

		case 29:
			cout << "4 of Diamonds" << endl;
		break;

		case 30:
			cout << "5 of Diamonds" << endl;
		break;

		case 31:
			cout << "6 of Diamonds" << endl;
		break;

		case 32:
			cout << "7 of Diamonds" << endl;
		break;

		case 33:
			cout << "8 of Diamonds" << endl;
		break;

		case 34:
			cout << "9 of Diamonds" << endl;
		break;

		case 35:
			cout << "10 of Diamonds" << endl;
		break;

		case 36:
			cout << "Jack of Diamonds" << endl;
		break;

		case 37:
			cout << "Queen of Diamonds" << endl;
		break;

		case 38:
			cout << "King of Diamonds" << endl;
		break;

		case 39:
			cout << "Ace of Diamonds" << endl;
		break;

		case 40:
			cout << "2 of Hearts" << endl;
		break;

		case 41:
			cout << "3 of Hearts" << endl;
		break;

		case 42:
			cout << "4 of Hearts" << endl;
		break;

		case 43:
			cout << "5 of Hearts" << endl;
		break;

		case 44:
			cout << "6 of Hearts" << endl;
		break;

		case 45:
			cout << "7 of Hearts" << endl;
		break;

		case 46:
			cout << "8 of Hearts" << endl;
		break;

		case 47:
			cout << "9 of Hearts" << endl;
		break;

		case 48:
			cout << "10 of Hearts" << endl;
		break;

		case 49:
			cout << "Jack of Hearts" << endl;
		break;

		case 50:
			cout << "Queen of Hearts" << endl;
		break;

		case 51:
			cout << "King of Hearts" << endl;
		break;

		case 52:
			cout << "Ace of Hearts" << endl;
		break;
	}
}

void swapHand(int hand[])
{
	for(int i = 0; i <= 5; i++)
	{
		getCard(deck[i]);
		hand[i] = deck[position++];
	}
}

Note, the formatting may turn out distorted.

Recommended Answers

All 2 Replies

check line 35. Syntax error.
Also, I doubt int cardNumber is not initialized anywhere.

Here's a rough schema that might work to evaluate a hand given your format.

Cards with number 1-13 are clubs, 14-26 are diamonds, etc. So if all cardsnumbers are within 1-13 you have a flush in clubs, 1-26 you have a flush in spades, etc. If all cardnumbers are within a given suit range and are also consecutive, then you have a straight flush and if all cards are within the given suit range, consecutive and the lowest value is 9 or 9 + x*13 then you have a royal flush in the given suit.

A pair would be if any two given cardnumbers differed by multiple of 13 (cardnumbers 1 and 14 would be a pair of twos. Three of a kind and 4 of a kind could be evaluated similarly.

A full house could also be found if you look for both a pair and 3 of a kind in the same hand.

Straights that aren't also flushes are going to be a bit more of a hassle with your format. I guess I'd try to convert the cardnumber of each card in the hand to a number between 1 and 13 inclusive by subtracting 13 from the given cardnumber until the value of the remainder is less than 14. Then I'd sort the numbers and see if the numbers are consecutive. If so, its a straight.

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.