1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int deal();
int main()
{
//char cards [14] = {'2','3','4','5','6','7','8','9','10','j','q','k','a','x'}
int card = 0;
int Dealer = 0;
int Player = 0;
char playerResponse = 0;
srand(time(NULL));
card = deal ();
Dealer = Dealer + card;
cout << "Dealer's first card is " << Dealer << "\n" ;
card = deal ();
Player = Player + card;
cout << "Your first card is " << Player << "\n";
card = deal ();
cout << "Your second card is " << card << "\n";
Player = Player + card;
cout << "Your total value is " << Player << "\n";
if ( Player > 21 )
cout << "\n" << "---Bust! You lost this hand.---";
if ( Player == 21)
cout << "\n" << "***YOU GOT BLACKJACK! YOU WIN!***";
if ( Dealer == 21 )
cout << "\n" << "---Dealer has Blackjack, you lost this hand.---";
if ( Dealer > 21 )
cout << "\n" << "***Dealer Busted! YOU WIN!***";
do
{
cout << "Enter (h) to hit for another card, or (s) to stand and keep your current hand.";
cin >> playerResponse;
card = deal ();
cout << "Your new card is " << card << "\n";
Player = Player + card;
cout << "Your total value is " << Player << "\n";
}while (Player < 21 && playerResponse != 's');
// if ( playerResponse == 'h')
if ( playerResponse == 's')
while ( Dealer <= 17 )
{
card = deal ();
Dealer = Dealer + card;
}
cout << " The dealer's final value is " << Dealer;
//while ( Dealer <= 17 )
//card = deal ();
//Dealer = Dealer + card;
}
int deal()
{
int card = 0;
card = rand() % 13 + 1;
return card;
}
|