For my final project in COSC I, I am supposed to make a semi-poker simulation. Right now I am having trouble determining when the given hand is a fullHouse. Here is the whole program so far.
#include <ctime> // time for random number seed
#include <iostream>
#include <cstdlib> // random number generator
#include <iomanip> // format output
using namespace std;
// function prototypes
struct ACard{
int Number;
char Picture;
};
void InitiateCard(ACard[]);
void ShuffleCard(ACard[]);
void DisplayCard(ACard[]);
void DrawCard(ACard[]);
void SortCard(ACard[]);
void CardAce(char);
void CardTwo(char);
void CardThree(char);
void CardFour(char);
void CardFive(char);
void CardSix(char);
void CardSeven(char);
void CardEight(char);
void CardNine(char);
void CardTen(char);
void CardJack(char);
void CardQueen(char);
void CardKing(char);
bool pairJack(ACard[]);
bool twoPair(ACard[]);
bool triple(ACard[]);
int straightorStraightFlush(ACard[]);
bool flush(ACard[]);
bool fullHouse(ACard[]);
bool fourCard(ACard[]);
bool royalFlush(ACard[]);
int makeBet(int);
int playGame(ACard[], int);
int determineReward(ACard[], int, int);
int main()
{
ACard card[52];
int seedMoney;
cout<< "Welcome to John Iannuzzi's Poker Game" << endl;
cout << "Enter an ammount of money to play with: " << endl;
cin >> seedMoney;
playGame(card, seedMoney);
}
int playGame(ACard Card[], int seed)
{
int bet;
char yesorno;
cout<< "Do you want to play? (Y,N)" << endl;
cin >> yesorno;
while((yesorno != 'Y') && (yesorno != 'y') && (yesorno != 'N') && (yesorno != 'n'))
{
cout << "That is an invalid input. Try again." << endl;
cout<< "Do you want to play? (Y,N)" << endl;
cin >> yesorno;
}
if(yesorno == 'Y' || yesorno == 'y')
{
bet = makeBet(seed);
InitiateCard(Card);
ShuffleCard(Card);
DisplayCard(Card);
DrawCard(Card);
DisplayCard(Card);
SortCard(Card);
seed = determineReward(Card, seed, bet);
playGame(Card, seed);
return 0;
}
else
{
cout << "Thank you and good bye." << endl;
return 0;
}
}
int determineReward(ACard card[], int seed, int bet)
{
bool win = true;
if (pairJack(card))
{
cout << "You got a pair of jacks!" << endl;
bet = bet * 1;
}
else if (twoPair(card) && !fullHouse(card) && !flush(card))
{
cout << "You got two pair!" << endl;
bet = bet * 2;
}
else if (triple(card) && !flush(card) && !fullHouse(card))
{
cout << "You got a triple!" << endl;
bet = bet * 4;
}
else if (straightorStraightFlush(card) == 1)
{
cout << "You got a straight!" << endl;
bet = bet * 6;
}
else if (flush(card) && !fullHouse(card))
{
cout << "You got a flush!" << endl;
bet = bet * 8;
}
else if (fullHouse(card))
{
cout << "You got a full house!" << endl;
bet = bet * 10;
}
else if (fourCard(card))
{
cout << "You got a four of a kind!" << endl;
bet = bet * 20;
}
else if(straightorStraightFlush(card) == 2)
{
cout << "You got a straight flush!" << endl;
bet = bet * 100;
}
else if(royalFlush(card))
{
cout << "You got a royal flush!" << endl;
bet = bet * 1000;
}
else
{
cout << "Sorry you didn't win anything." << endl;
cout << "Your initial balance was: $" << seed << endl;
seed = seed - bet;
cout << "Your current balance is: $" << seed << endl;
cout << "You lost: $" << bet << endl;
win = false;
}
if (win == true)
{
cout << "Your inintial balance was: $" << seed << endl;
seed = seed + bet;
cout << "Your current balace is: $" << seed << endl;
cout << "You won: $" << bet << endl;
}
return seed;
}
void InitiateCard(ACard n[])
{
int cardCount = 1;
for (int i = 0; i < 13; i++){
n[i].Picture = 3;
n[i].Number = i + 1;
}
for (int a = 13; a < 26; a++){
n[a].Picture = 4;
n[a].Number = cardCount;
cardCount++;
}
cardCount = 1;
for(int b = 26; b < 39; b++){
n[b].Picture = 5;
n[b].Number = cardCount;
cardCount++;
}
cardCount = 1;
for(int c = 39; c < 52; c++){
n[c].Picture = 6;
n[c].Number = cardCount;
cardCount++;
}
}
int makeBet(int seed)
{
int bet;
cout << "How much do you want to bet?" << endl;
cin >> bet;
while (bet > seed)
{
cout << "Sorry you do not have that much. Please enter a bet within the given seed money." << endl;
cin >> bet;
}
return bet;
}
void ShuffleCard(ACard n[])
{
srand(time(0));
for(int i = 0; i < 52; i++)
{
int j = rand() % 52;
int temp = n[i].Number;
int temp2 = n[i].Picture;
n[i].Number = n[j].Number;
n[i].Picture = n[j].Picture;
temp = n[j].Number;
temp2 = n[j].Picture;
}
}
void CardAce(char Pic)
{
cout <<"---------"<<endl;
cout <<"|"<<"A"<<setw(7)<<"|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(4)<<Pic<<setw(4)<<"|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(7)<< "A"<<"|"<<endl;
cout <<"---------"<<endl;
}
void CardTwo(char Pic)
{
cout <<"---------"<<endl;
cout <<"|"<<"2"<<setw(7)<<"|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(3)<<Pic<<setw(5)<<"|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(5)<<Pic<<setw(3)<<"|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(7)<< "2"<<"|"<<endl;
cout <<"---------"<<endl;
}
void CardThree(char Pic)
{
cout <<"---------"<<endl;
cout <<"|"<<"3"<<setw(7)<<"|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(4)<<Pic<<setw(4)<<"|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(4)<<Pic<<setw(4)<<"|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(4)<<Pic<<setw(4)<<"|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(7)<< "3"<<"|"<<endl;
cout <<"---------"<<endl;
}
void CardFour(char Pic)
{
cout <<"---------"<<endl;
cout <<"|"<<"4"<<setw(7)<<"|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(2)<<Pic<<setw(4)<< Pic << setw(2) << "|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(2)<<Pic<<setw(4)<< Pic << setw(2) << "|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(7)<< "4"<<"|"<<endl;
cout <<"---------"<<endl;
}
void CardFive(char Pic)
{
cout <<"---------"<<endl;
cout <<"|"<<"5"<<setw(7)<<"|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(2)<<Pic<<setw(4)<< Pic << setw(2) << "|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(4)<<Pic<<setw(4)<<"|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(2)<<Pic<<setw(4)<< Pic << setw(2) << "|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(7)<< "5"<<"|"<<endl;
cout <<"---------"<<endl;
}
void CardSix(char Pic)
{
cout <<"---------"<<endl;
cout <<"|"<<"6"<<setw(7)<<"|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(2)<<Pic<<setw(4)<< Pic << setw(2) << "|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(2)<<Pic<<setw(4)<< Pic << setw(2) << "|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(2)<<Pic<<setw(4)<< Pic << setw(2) << "|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(7)<< "6"<<"|"<<endl;
cout <<"---------"<<endl;
}
void CardSeven(char Pic)
{
cout <<"---------"<<endl;
cout <<"|"<<"7"<<setw(7)<<"|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(2)<<Pic<<setw(4)<< Pic << setw(2) << "|"<<endl;
cout <<"|"<<setw(4)<<Pic<<setw(4)<<"|"<<endl;
cout <<"|"<<setw(2)<<Pic<<setw(4)<< Pic << setw(2) << "|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(2)<<Pic<<setw(4)<< Pic << setw(2) << "|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(7)<< "7"<<"|"<<endl;
cout <<"---------"<<endl;
}
void CardEight(char Pic)
{
cout <<"---------"<<endl;
cout <<"|"<<"8"<<setw(7)<<"|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(2)<<Pic<<setw(4)<< Pic << setw(2) << "|"<<endl;
cout <<"|"<<setw(4)<<Pic<<setw(4)<<"|"<<endl;
cout <<"|"<<setw(2)<<Pic<<setw(4)<< Pic << setw(2) << "|"<<endl;
cout <<"|"<<setw(4)<<Pic<<setw(4)<<"|"<<endl;
cout <<"|"<<setw(2)<<Pic<<setw(4)<< Pic << setw(2) << "|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(7)<< "8"<<"|"<<endl;
cout <<"---------"<<endl;
}
void CardNine(char Pic)
{
cout <<"---------"<<endl;
cout <<"|"<<"9"<<setw(7)<<"|"<<endl;
cout <<"|"<<setw(2)<<Pic<<setw(4)<< Pic << setw(2) << "|"<<endl;
cout <<"|"<<setw(4)<<Pic<<setw(4)<<"|"<<endl;
cout <<"|"<<setw(2)<<Pic<<setw(4)<< Pic << setw(2) << "|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(2)<<Pic<<setw(4)<< Pic << setw(2) << "|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(2)<<Pic<<setw(4)<< Pic << setw(2) << "|"<<endl;
cout <<"|"<<setw(7)<< "9"<<"|"<<endl;
cout <<"---------"<<endl;
}
void CardTen(char Pic)
{
cout <<"---------"<<endl;
cout <<"|"<<"10"<<setw(6)<<"|"<<endl;
cout <<"|"<<setw(2)<<Pic<<setw(4)<< Pic << setw(2) << "|"<<endl;
cout <<"|"<<setw(4)<<Pic<<setw(4)<<"|"<<endl;
cout <<"|"<<setw(2)<<Pic<<setw(4)<< Pic << setw(2) << "|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(2)<<Pic<<setw(4)<< Pic << setw(2) << "|"<<endl;
cout <<"|"<<setw(4)<<Pic<<setw(4)<<"|"<<endl;
cout <<"|"<<setw(2)<<Pic<<setw(4)<< Pic << setw(2) << "|"<<endl;
cout <<"|"<<setw(7)<< "10"<<"|"<<endl;
cout <<"---------"<<endl;
}
void CardJack(char Pic)
{
cout <<"---------"<<endl;
cout <<"|"<<Pic << "J"<<setw(6)<<"|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(6)<< "J"<< Pic <<"|"<<endl;
cout <<"---------"<<endl;
}
void CardQueen(char Pic)
{
cout <<"---------"<<endl;
cout <<"|"<<Pic << "Q"<<setw(6)<<"|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(6)<< "Q"<< Pic << "|"<<endl;
cout <<"---------"<<endl;
}
void CardKing(char Pic)
{
cout <<"---------"<<endl;
cout <<"|"<<Pic << "K"<<setw(6)<<"|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(8)<<"|"<<endl;
cout <<"|"<<setw(6)<< "K"<<Pic << "|"<<endl;
cout <<"---------"<<endl;
}
// Insertion sort
void SortCard(ACard FiveCard[])
{
ACard InCard;
int pos;
char KeyPic;
for (int i=1; i<5; i++)
{
InCard =FiveCard[i];
pos = i;
while (pos >0 && InCard.Number < FiveCard[pos-1].Number)
{
FiveCard[pos] = FiveCard[pos -1];
pos--;
}
FiveCard[pos]=InCard;
}
}
void DisplayCard(ACard n[])
{
n[0].Number = 4;
n[1].Number = 4;
n[2].Number = 4;
n[3].Number = 7;
n[4].Number = 7;
n[0].Picture = 3;
n[1].Picture = 3;
n[2].Picture = 3;
n[3].Picture = 3;
n[4].Picture = 3;
for (int i = 0; i<5; i++)
{
switch (n[i].Number)
{
case 1:CardAce(n[i].Picture);
break;
case 2:CardTwo(n[i].Picture);
break;
case 3:CardThree(n[i].Picture);
break;
case 4:CardFour(n[i].Picture);
break;
case 5:CardFive(n[i].Picture);
break;
case 6:CardSix(n[i].Picture);
break;
case 7:CardSeven(n[i].Picture);
break;
case 8:CardEight(n[i].Picture);
break;
case 9:CardNine(n[i].Picture);
break;
case 10:CardTen(n[i].Picture);
break;
case 11:CardJack(n[i].Picture);
break;
case 12:CardQueen(n[i].Picture);
break;
case 13:CardKing(n[i].Picture);
break;
}
}
}
void DrawCard(ACard n[])
{
int yesorno = 2;
int deckCount = 5;
int temp;
char temp2;
for (int i = 0; i < 5; i++)
{
if(n[i].Number < 11 && n[i].Number > 1)
cout<< n[i].Number << n[i].Picture << ": Hold (1) or Redraw (0)?" << endl;
else if (n[i].Number == 1)
cout<< "A" << n[i].Picture << ": Hold (1) or Redraw (0)?" << endl;
else if (n[i].Number == 11)
cout<< "J" << n[i].Picture << ": Hold (1) or Redraw (0)?" << endl;
else if (n[i].Number == 12)
cout<< "Q" << n[i].Picture << ": Hold (1) or Redraw (0)?" << endl;
else if (n[i].Number == 13)
cout<< "K" << n[i].Picture << ": Hold (1) or Redraw (0)?" << endl;
cin >> yesorno;
while (yesorno > 1 || yesorno < 0){
cout << "Invalid number please try again." << endl;
if(n[i].Number < 11 && n[i].Number > 1)
cout<< n[i].Number << n[i].Picture << ": Hold (1) or Redraw (0)?" << endl;
else if (n[i].Number == 1)
cout<< "A" << n[i].Picture << ": Hold (1) or Redraw (0)?" << endl;
else if (n[i].Number == 11)
cout<< "J" << n[i].Picture << ": Hold (1) or Redraw (0)?" << endl;
else if (n[i].Number == 12)
cout<< "Q" << n[i].Picture << ": Hold (1) or Redraw (0)?" << endl;
else if (n[i].Number == 13)
cout<< "K" << n[i].Picture << ": Hold (1) or Redraw (0)?" << endl;
cin >> yesorno;
}
if(yesorno == 0)
{
n[i].Number = n[deckCount].Number;
n[i].Picture = n[deckCount].Picture;
deckCount++;
}
}
}
bool pairJack(ACard n[])
{
int jackCount = 0;
for(int i = 0; i < 5; i++)
{
if(n[i].Number == 11)
jackCount++;
}
if (jackCount == 2 && !twoPair(n) && !triple(n) && !fullHouse(n))
return true;
else
return false;
}
bool twoPair(ACard n[])
{
bool pair1 = false;
bool pair2 = false;
int savePos;
for(int i = 1; i < 5; i++)
{
if(n[i].Number == n[i - 1].Number && !pair1)
{
pair1 = true;
savePos = i + 2;
}
else if(pair1 == true)
i = 4;
}
if(pair1 == true && savePos < 5)
{
for(int a = savePos; a < 5; a++)
if(n[a].Number == n[a - 1].Number)
pair2 = true;
}
if(pair1 && pair2)
return true;
else
return false;
}
bool triple(ACard n[])
{
int tripleCount = 0;
for(int i = 2; i < 5; i++)
{
if(n[i].Number == n[i-1].Number && n[i-2].Number == n[i].Number)
{
tripleCount++;
}
}
if(tripleCount == 1)
return true;
else
return false;
}
int straightorStraightFlush(ACard n[])
{
int count = 0;
int straightCount = 0;
for(int i = 1; i < 5; i++)
{
if(n[i].Number == n[i-1].Number)
count++;
}
if(count == 4)
{
for(int i = 1; i < 5; i++)
{
if(n[i].Picture == n[i - 1].Picture)
straightCount++;
}
if(straightCount = 4)
return 2;
else
return 1;
}
else
return 0;
}
bool flush(ACard n[])
{
int flushCount = 0;
for(int i = 1; i < 5; i++)
{
if(n[i].Picture == n[i - 1].Picture)
flushCount++;
}
if(flushCount == 4)
return true;
else
return false;
}
bool fullHouse(ACard n[])
{
int count = 0;
int a = 0;
bool hasTwo = false;
bool hasThree = false;
while(a < 5){
for(int i = 0; i < 5; i++)
{
if(a != i && n[a].Number == n[i].Number && count != 1)
count++;
else if (count == 1)
{
if(n[a].Number == n[i + 1].Number)
{
hasThree = true;
count = 0;
a = a + 2;
}
else if(hasTwo && hasThree)
a = 5;
else
{
hasTwo = true;
count = 0;
a++;
}
}
}
if(hasTwo && hasThree)
return true;
else
return false;
}
}
bool fourCard(ACard n[])
{
int fourCount = 0;
for(int i = 3; i < 5; i++)
{
if(n[i].Number == n[i - 1].Number && n[i].Number == n[i - 2].Number && n[i].Number == n[i - 3].Number)
{
fourCount++;
}
}
if (fourCount == 1)
return true;
else
return false;
}
bool royalFlush(ACard n[])
{
int aceCount = 0;
int tenCount = 0;
int jackCount = 0;
int queenCount = 0;
int kingCount = 0;
int picCount = 0;
for (int i = 0; i < 5; i++)
{
if(n[i].Number == 1)
aceCount++;
else if(n[i].Number == 10)
tenCount++;
else if(n[i].Number == 11)
jackCount++;
else if(n[i].Number == 12)
queenCount++;
else if(n[i].Number == 13)
kingCount++;
}
for(int a = 1; a < 5; a++)
{
if(n[a].Picture == n[a - 1].Picture)
picCount++;
}
if (picCount == 4 && aceCount == 1 && tenCount == 1 && jackCount == 1 && queenCount == 1 && kingCount == 1){
return true;
}
else
return false;
}
Can Anyone help me? Also I have display card set up in a way that tests the fullHouse function.