Advertisement
Guest User

XY BlackJack

a guest
Oct 17th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <random>
  3. #include <cstdlib>
  4. using namespace std;
  5.  
  6. int main() {
  7. int value = 1;
  8. while (value == 1){
  9. cout<<"Enter how much you would like to bet!! :";
  10. int betmoney;
  11. cin>>betmoney;
  12.  
  13. char card_type[4][15] = {
  14. "Diamonds", "Hearts", "Spades", "Clubs"
  15. };
  16. int card_number[13] = {
  17. 1,2,3,4,5,6,7,8,9,10,10,10,10
  18. };
  19. char card_name[13][15] = {
  20. "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"
  21. };
  22.  
  23. int playerrandomcard1;
  24. playerrandomcard1 = rand() % 12 + 0;
  25. \
  26. int playerrandomsuit1;
  27. playerrandomsuit1 = rand() % 3 + 0;
  28.  
  29. int playerrandomcard2;
  30. playerrandomcard2 = rand() % 12 + 0;
  31.  
  32. int playerrandomsuit2;
  33. playerrandomsuit2 = rand() % 3 + 0;
  34.  
  35. int playertotal = playerrandomcard1 + playerrandomcard2;
  36.  
  37. cout <<"Your first card is a "<<card_name[playerrandomcard1]<<" of "<<card_type[playerrandomsuit1]<<"!"<<endl;
  38.  
  39. cout <<"Your second card is a "<<card_name[playerrandomcard2]<<" of "<<card_type[playerrandomsuit2]<<"!\n"<<endl;
  40.  
  41. int dealerrandomcard1;
  42. dealerrandomcard1 = rand() % 12 + 0;
  43.  
  44. int dealerrandomsuit1;
  45. dealerrandomsuit1 = rand() % 3 + 0;
  46.  
  47. int dealerrandomcard2;
  48. dealerrandomcard2 = rand() % 12 + 0;
  49.  
  50. int dealerrandomsuit2;
  51. dealerrandomsuit2 = rand() % 3 + 0;
  52.  
  53. int dealertotal = dealerrandomcard1 + dealerrandomcard2;
  54.  
  55. cout <<"The Dealer's first card is a "<<card_name[dealerrandomcard1]<<" of "<<card_type[dealerrandomsuit1]<<"!"<<endl;
  56.  
  57. cout <<"The Dealer's second card is unknown!"<<endl;
  58.  
  59. int value3 = 5;
  60. while (playertotal < 21 && value3 == 5){
  61. cout<<"Will you hit or stand? enter 1 for hit and 2 for stand: ";
  62. int hitchoice;
  63. cin>> hitchoice;
  64. if (hitchoice == 1){
  65. int newplayercard = rand() % 12 + 0;
  66. int newplayersuit = rand() % 3 + 0;
  67. playertotal = playertotal + newplayercard;
  68.  
  69. cout <<"Your new card is a "<<card_name[newplayercard]<<" of "<<card_type[newplayersuit]<<" ! \n";
  70. cout<<"Your new total is "<<playertotal<<"."<<endl;
  71. if (playertotal > 21){
  72. cout<<"Sorry, you lose!\n";
  73. cout<<"You have lost your "<<betmoney<<" dollars.";
  74. break;
  75. }
  76. else{
  77. continue;
  78. }
  79. }
  80. else if (hitchoice == 2){
  81. cout <<"The dealers second card is a "<<card_name[dealerrandomcard2]<<" of "<<card_type[dealerrandomsuit2]<<"!\n"<<endl;
  82. while (dealertotal <= 17){
  83.  
  84. int dealerhitcard = rand() % 12 + 0;
  85. int dealerhitsuit = rand() % 3 + 0;
  86.  
  87. cout <<"The dealer hit a "<<card_name[dealerhitcard]<<" of "<<card_type[dealerhitsuit]<<" ! \n";
  88. dealertotal = dealertotal + dealerhitcard;
  89. cout<<"The dealers total is now "<<dealertotal<<"! \n";
  90. if (dealertotal > 21){
  91. cout<<"The dealer busted! you win!\n";
  92. cout<<"You won "<<betmoney * 2<< " dollars!";
  93. value3 = 6;
  94. }
  95. else if (dealertotal > 17){
  96. value3 = 6;
  97. }
  98. }
  99. }
  100. if (playertotal > dealertotal){
  101. cout<<"You win! \n";
  102. cout<<"You won "<<betmoney * 2<< " dollars!";
  103. }
  104. else if (playertotal < dealertotal){
  105. cout<<"You lose! \n";
  106. cout<<"You lost your "<<betmoney<< " dollars.";
  107. }
  108. else{
  109. cout<<"Its a tie!\n";
  110. cout<<"No money lost or won";
  111. }
  112. }
  113. cout<<"Would you like to play again? enter 1 for yes and 2 for no";
  114. int playagainchoice;
  115. cin>>playagainchoice;
  116. if (playagainchoice == 1){
  117. cout<<"OK \n";
  118. }
  119. else if (playagainchoice == 2){
  120. value = 2;
  121. }
  122. }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement