Guest User

Untitled

a guest
Dec 10th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.01 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int hand_amount;
  5. char cards;
  6. char card1;
  7. char card2;
  8. char card3;
  9. char card4;
  10. char card5;
  11. int final_hand;
  12. bool repeat = true;
  13. char y_n;
  14. int score;
  15. int cards_in_deck(char cards);
  16.  
  17. int main()
  18. {
  19.     while(repeat)
  20.     {
  21.         cout << "Enter how many card you have in your hand (Choose from 2 to 5 cards!):" << endl;
  22.         cin >> hand_amount;
  23.         final_hand = 0;
  24.  
  25.         if(hand_amount < 2 or hand_amount > 5)
  26.         {
  27.             cout << "Invalid number of cards chosen! Choose again." << endl;
  28.             continue;
  29.         }
  30.  
  31.         cout << "Now enter which cards you have in your hand:" << endl << "(The cards range from 2 to 9 - T, J, Q, K score 10 - A scores either 1 or 11 depending on the hand's score)" << endl;
  32.  
  33.         if(hand_amount == 2)
  34.         {
  35.             cout << "Card 1: ";
  36.             cin >> card1;
  37.             final_hand = final_hand + cards_in_deck(card1);
  38.             cout << "Card 2: ";
  39.             cin >> card2;
  40.             final_hand = final_hand + cards_in_deck(card2);
  41.         }
  42.  
  43.         else if(hand_amount == 3)
  44.         {
  45.             cout << "Card 1: ";
  46.             cin >> cards;
  47.             cout << "Card 2: ";
  48.             cin >> cards;
  49.             cout << "Card 3: ";
  50.             cin >> cards;
  51.         }
  52.  
  53.         else if(hand_amount == 4)
  54.         {
  55.             cout << "Card 1: ";
  56.             cin >> cards;
  57.             cout << "Card 2: ";
  58.             cin >> cards;
  59.             cout << "Card 3: ";
  60.             cin >> cards;
  61.             cout << "Card 4: ";
  62.             cin >> cards;
  63.         }
  64.  
  65.         else if(hand_amount == 5)
  66.         {
  67.             cout << "Card 1: ";
  68.             cin >> cards;
  69.             cout << "Card 2: ";
  70.             cin >> cards;
  71.             cout << "Card 3: ";
  72.             cin >> cards;
  73.             cout << "Card 4: ";
  74.             cin >> cards;
  75.             cout << "Card 5: ";
  76.             cin >> cards;
  77.         }
  78.  
  79.         if(final_hand > 21)
  80.         {
  81.             cout << "You're busted!" << endl;
  82.         }
  83.         else
  84.         {
  85.             cout << "Your final hand scores: " << final_hand << endl;
  86.         }
  87.  
  88.         do
  89.         {
  90.             cout << "Do you want to try again? (y or Y for Yes , n or N for No)" << endl;
  91.             cin >> y_n;
  92.  
  93.             switch(y_n)
  94.             {
  95.                 case'y':
  96.                 case'Y':
  97.                 {
  98.                     repeat = true;
  99.                     break;
  100.                 }
  101.                 case'n':
  102.                 case'N':
  103.                 {
  104.                     repeat = false;
  105.                     break;
  106.                 }
  107.                 default:
  108.                 {
  109.                     break;
  110.                 }
  111.             }
  112.         }
  113.         while(false);
  114.         }
  115.  
  116.     return 0;
  117. }
  118.  
  119. int cards_in_deck(char cards)
  120. {
  121.     switch(cards)
  122.         {
  123.             case'2':
  124.             {
  125.                 score = 2;
  126.             }
  127.             case'3':
  128.             {
  129.                 score = 3;
  130.             }
  131.             case'4':
  132.             {
  133.                 score = 4;
  134.             }
  135.             case'5':
  136.             {
  137.                 score = 5;
  138.             }
  139.             case'6':
  140.             {
  141.                 score = 6;
  142.             }
  143.             case'7':
  144.             {
  145.                 score = 7;
  146.             }
  147.             case'8':
  148.             {
  149.                 score = 8;
  150.             }
  151.             case'9':
  152.             {
  153.                 score = 9;
  154.             }
  155.             case't':
  156.             case'T':
  157.             case'j':
  158.             case'J':
  159.             case'q':
  160.             case'Q':
  161.             case'k':
  162.             case'K':
  163.             {
  164.                 score = 10;
  165.             }
  166.             case'a':
  167.             case'A':
  168.             {
  169.                 if(final_hand > 21)
  170.                 {
  171.                     score = 1;
  172.                 }
  173.                 else
  174.                 {
  175.                     score = 11;
  176.                 }
  177.             }
  178.         }
  179.     return score;
  180. }
Add Comment
Please, Sign In to add comment