so basically the thing is nearly complete, and im just trying to get it to work, im pretty sure i just havent closed off some statments and such, but i cannot for the life of me see where, or how to get the error messages to leave me alone in peace
if you could have a look over, tell me where it needs changing, that would be great and i will send you unicorn, thanks in advance.
#include <iostream>
#include <ctime> //For time generator
void Cardshuffle(bool DealtCards[]);
void PrintCard(int iCard);
void PrintHand(int iaHand[], const int ConsDealtCard);
int GetNextCard(bool DealtCards[]);
int ScoreHand(int iaHand[], const int ConsDealtCard);
void game(); // Actual Game Routine
void MenuSystem(); // Menu Routine For Game
void PrintScoresAndHands(int iaHouseHand[], const int kiHouseDealtCards, int iaPlayerHand[], const int kiPlayerDealtCards); //Print total player and computer scores
int main()
{
using namespace std;
{
time_t qTime;
time(&qTime);
srand(qTime); //Using the time to change the number that is generated, this means it will always be different
char choice;
do
{
MenuSystem();
cin >> choice;
if (choice == '1')
{
game();
}
} while (choice != '2');
cout << endl;
system ("pause");
return 0;
void MenuSystem();
{
cout << "--------------------------------------------------------" << endl;
cout << "-------------- Want To Play BlackJack ? ----------------" << endl;
cout << "--------------------------------------------------------" << endl;
cout << "choices \n\n"
<< "Press 1 To Play Black Jack" << endl
<< "Press 2 To View Back Jack Rules" << endl
<< "Press 3 To Quit Black Jack" << endl << endl
<< "Enter Choice : ";
void game();
bool DealtCards[52];
int iHouseDealtCards = 0;
int iaHouseHand[12];
int iPlayerDealtCards = 0;
int iaPlayerHand[12];
// Loop once for each hand
while (true) {
// "Cardshuffle" the cards; set them all to undealt
Cardshuffle(DealtCards);
// Deal the hands. Get two cards for each
iaPlayerHand[0] = GetNextCard(DealtCards);
iaHouseHand[0] = GetNextCard(DealtCards);
iaPlayerHand[1] = GetNextCard(DealtCards);
iaHouseHand[1] = GetNextCard(DealtCards);
iHouseDealtCards = 2;
iPlayerDealtCards = 2;
// Signal a new hand.
cout << "--------------------------------------------------------" << endl;
cout << "-----------------------New Hand-------------------------" << endl;
cout << "--------------------------------------------------------" << endl;
char cPlayerChoice;
bool bPlayerHits = true;
int iPlayerScore = ScoreHand(iaPlayerHand, iPlayerDealtCards);
// Get Player's hits. Calculate the score and redisplay after each hit.
do {
// Print the dealt cards, but only the House's second card.
cout << "House's Hand" << endl;
cout << "** ";
PrintCard(iaHouseHand[1]);
cout << endl;
cout << "Player's Hand: Score = " << ScoreHand(iaPlayerHand, iPlayerDealtCards) << endl;
PrintHand(iaPlayerHand, iPlayerDealtCards);
// Ask the Player whether he wants a hit or to stay
cout << "Hit Me(h) or Leave It(l): ";
cin >> cPlayerChoice;
if (cPlayerChoice == 'h')
{
iaPlayerHand[iPlayerDealtCards] = GetNextCard(DealtCards);
++iPlayerDealtCards;
} else if (cPlayerChoice == 'l')
{
bPlayerHits = false;
} else
{
cout << "Sorry: Try Again!" << endl;
}
cout << endl;
// Get the Player's current score to update and check for bust.
iPlayerScore = ScoreHand(iaPlayerHand, iPlayerDealtCards);
} while (bPlayerHits && iPlayerScore < 22);
// Once the player is done taking hits, check whether he busted
if (iPlayerScore > 21)
{
// The Player busted. The House wins.
cout << "**** The House Wins!!! ****" << endl;
PrintScoresAndHands(iaHouseHand, iHouseDealtCards, iaPlayerHand, iPlayerDealtCards);
} else
{
// If the player hasnt gone bust, then the house takes hits below 17
int iHouseScore = ScoreHand(iaHouseHand, iHouseDealtCards);
while (iHouseScore < 17)
{
iaHouseHand[iHouseDealtCards] = GetNextCard(DealtCards);
++iHouseDealtCards;
iHouseScore = ScoreHand(iaHouseHand, iHouseDealtCards);
}
bool bHouseBusts = (iHouseScore > 21);
if (bHouseBusts)
{
// The House busted. Player wins
cout << "**** The Player Wins!!! ****" << endl;
PrintScoresAndHands(iaHouseHand, iHouseDealtCards, iaPlayerHand, iPlayerDealtCards);
} else
{
// Compare scores and determine the winner
if (iPlayerScore == iHouseScore)
{
// Tie. This is called a "push."
cout << "**** Tie!!! ****" << endl;
PrintScoresAndHands(iaHouseHand, iHouseDealtCards, iaPlayerHand, iPlayerDealtCards);
} else if (iPlayerScore > iHouseScore)
{
// The Player wins
cout << "**** The Player Wins!!! ****" << endl;
PrintScoresAndHands(iaHouseHand, iHouseDealtCards, iaPlayerHand, iPlayerDealtCards);
} else
{
// The House wins
cout << "**** The House Wins!!! ****" << endl;
PrintScoresAndHands(iaHouseHand, iHouseDealtCards, iaPlayerHand, iPlayerDealtCards);
}
}
}
}
return EXIT_SUCCESS;
}
void Cardshuffle(bool DealtCards[])
{
for (int iIndex = 0; iIndex < 52; ++iIndex)
{
DealtCards[iIndex] = false;
}
}
void PrintCard(int iCard)
{
using namespace std;
// Print Rank
const int kiRank = (iCard % 13);
if (kiRank == 0)
{
cout << 'A';
} else if (kiRank < 9)
{
cout << (kiRank + 1);
} else if (kiRank == 9)
{
cout << 'T';
} else if (kiRank == 10)
{
cout << 'J';
} else if (kiRank == 11)
{
cout << 'Q';
} else
{
cout << 'K';
} // Print Suit
}
const int kiSuit = (iCard/13);
if (kiSuit == 0)
{
cout << '\x05';
} else if (kiSuit == 1) // clubs
{
cout << '\x04';
} else if (kiSuit == 2) //diamonds
{
cout << '\x03'; //hearts
} else {
cout << '\x06'; //spades
}
}
void PrintHand(int iaHand[], const int ConsDealtCard)
{
using namespace std;
for (int iCardIndex = 0; iCardIndex < ConsDealtCard; ++iCardIndex)
{
const int kiNextCard = iaHand[iCardIndex];
PrintCard(kiNextCard);
cout << " ";
}
cout << endl;
}
int GetNextCard(bool DealtCards[])
{
bool bCardDealt = true;
int iNewCard = -1;
do
{
iNewCard = (rand() % 52);
if (!DealtCards[iNewCard])
{
bCardDealt = false;
}
} while (bCardDealt);
return iNewCard;
}
int ScoreHand(int iaHand[], const int ConsDealtCard)
{
int iAceCount = 0;
int iScore = 0;
for (int iCardIndex = 0; iCardIndex < ConsDealtCard; ++iCardIndex)
{
const int kiNextCard = iaHand[iCardIndex];
const int kiRank = (kiNextCard % 13);
if (kiRank == 0)
{
++iAceCount;
++iScore;
} else if (kiRank < 9)
{
iScore = iScore + (kiRank + 1);
} else
{
iScore = iScore + 10;
}
}
while (iAceCount > 0 && iScore < 12)
{
--iAceCount;
iScore = iScore + 10;
}
return iScore;
void PrintScoresAndHands(int iaHouseHand[], const int kiHouseDealtCards, int iaPlayerHand[], const int kiPlayerDealtCards)
{
using namespace std;
cout << "House's Hand: Score = " << ScoreHand(iaHouseHand, kiHouseDealtCards) << endl;
PrintHand(iaHouseHand, kiHouseDealtCards);
cout << "Player's Hand: Score = " << ScoreHand(iaPlayerHand, kiPlayerDealtCards) << endl;
PrintHand(iaPlayerHand, kiPlayerDealtCards);
cout << endl;
}