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.