I dont know why, but this program I wrote is having a problem. it has a problem converting an Ace from 11 to 1 when the players have more than 21. if you could look over this, I would appreciate it.
#include <iostream>
#include <ctime>
using namespace std;
double Card = 0;
char cardA;
int YN = 1;
bool Ace = false;
int Play = 1;
double pHand = 0;
double dHand = 0;
double Chips = 1000;
double bet = 0;
int Win = 0;
void cardT()
{
int KQJ = 0;
if (Card == 11)
{
cout << "Dealer draws a Jack\n";
Card = 10;
KQJ = 1;
}
if (Card==12)
{
cout << "Dealer draws a Queen\n";
Card = 10;
KQJ = 1;
}
if (Card==13)
{
cout << "Dealer draws a King\n";
Card = 10;
KQJ = 1;
}
if (Card == 1)
{
cout << "Dealer draws an Ace\n";
Card = 11;
Ace = true;
KQJ = 1;
}
if (KQJ != 1)
{
cout << "Dealer draws a "<< Card << endl;
}
}
void dDraw()
{
Card = ( rand() %13) + 1; //Dealer Draws
cardT();
dHand = dHand+Card;
if ((dHand > 21) && (Ace = true))
{
dHand = dHand - 10;
Ace= false;
}
cout << "dealer has " << dHand<< endl << endl;
}
void pDraw()
{
Card = ( rand() %13) + 1; //Player Draws
cardT();
pHand = pHand+Card;
if ((dHand >21) && (Ace = true))
{
pHand = pHand - 10;
Ace=false;
}
cout << "player has " << pHand<< endl << endl;
}
int main()
{
cout << "Welcome to Blackjack. Would you like to play?\n";
cout << " 1.Yes\n 2.No\n";
cin >> Play;
while (Play != 2)
{
cout << "You have $" << Chips << " in chips.\n";
cout << "Place your bet\n";
cin >> bet;
while (Chips < bet)
{
cout << "Please enter fewer chips than you have.\n";
cout << "Place your bet\n";
cin >> bet;
}
srand( time( NULL ) );
pDraw();
dDraw();
pDraw();
dDraw();
while (YN == 1)
{
if (pHand < 21)
{
cout << "Would you like another card?\n 1.Hit me \n 2.Stay \n";
cin >> YN;
cout << endl;
}
if (pHand == 21)
{
cout << "Winner! Winner! Chicken dinner!\n\n";
YN=2;
Win=1;
}
if (pHand >= 22)
{
cout << "Player busts. Dealer wins\n\n";
pHand=0;
YN=2;
Win=2;
}
if (YN == 1)
{
cout << "Very well\n";
pDraw();
}
if ((YN != 1) && (pHand != 0) && (pHand != 21))
{
while (dHand <= 17)
{
dDraw();
}
if (dHand == 21)
{
cout << "Dealer has BlackJack Dealer wins.\n\n" ;
Win=2;
}
if ((dHand >= 22) && (dHand != 21))
{
cout << "Dealer busts. Player wins\n\n";
dHand=0;
Win=1;
}
if ((dHand != 0) && (pHand !=0) && (dHand != 21) && (pHand != 21))
{
if (pHand<dHand)
{
cout << "Dealer wins.\n\n";
Win=2;
}
if (pHand>dHand)
{
cout << "Player wins.\n\n";
Win=1;
}
if (pHand==dHand)
{
cout << "Game ends in tie.\n\n";
}
}
}
}
if (Win == 1)
{
Chips = Chips + bet;
}
if (Win == 2)
{
Chips = Chips - bet;
}
cout << "You have $" << Chips << " in chips.\n" ;
Ace=0;
Win = 0;
dHand = 0;
pHand = 0;
YN = 1;
cout << "Would you like to play again?\n 1.Yes\n 2.No\n";
cin >> Play;
if ((Chips <= 0) && (Play == 1))
{
Play = 2;
cout << "Sorry, but you are out of chips.\n";
}
}
cout << "Thank you for playing!\n";
system ("pause");
return 0;
}
lenghty, isn't it?:icon_eek: