title: Blackjack Program for C++. How can I add multiple char values in the switch statements?
body: <p>Write a program that scores a blackjack hand. In blackjack, a player receives from two to five cards. (The player decides how many, but that has no effect on this exercise.) The cards 2 through 10 are scored as 2 through 10 points each. The face cards, jack, queen, and king are scored as 10 points. The goal is to come as close to a score of 21 as possible without going over 21. Hence, any score over 21 is called "busted." The ace can count as either 1 or 11, whichever is better for the user. For example, an ace and a 10 can be scored as either 11 or 21. Since 21 is a better score, this hand is scored as 21. An ace and two 8' s can be scored as either 17 or 27. Since 27 is a "busted" score, this hand is scored as 17.<br>
  The user is asked how many cards she or he has, and the user responds with one of the integers 2, 3, 4, or 5. The user is then asked for the card values.
  Card values are 2 through 10, jack, queen, king, and ace. A good way to handle input is to use the type char so that the card input 2, for example, is read as the character '2', rather than as the number 2. Input the values 2 through 9 as the characters '2' through '9'. Input the values 10, jack, queen, king, and ace as the characters 't ', 'j', 'q', 'k', and 'a'. An ace can also be entered as a '1'. Be sure to allow upper as well as lowercase letters as input.<br>
    After reading in the values, the program should convert them from character values to numeric card scores, taking special care for aces. The output is either a number between 2 and 21 (inclusive) or the word Busted. Use functions where appropriate. Use a switch statement to determine the correct value for a card. Your program should include a loop that lets the user repeat this calculation until the user says she or he is done.</p>
  
  <p><strong>Example Output:</strong>
  Enter the number of cards: 3<br>
  Enter cards: a78<br>
  The value of your hand is 16.</p>
  
  <p>Would you like to score another hand (Y or N)?: y<br>
  Enter the number of cards: 4<br>
  Enter cards: 354K<br>
  You are BUSTED!</p>
  
  <p>I'm stuck on adding the values of the cards.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  using namespace std;
  
  int main()
  {
  int cards_in_hand;
  int value, total_value = 0;
  std::string card_value;
  
  
  cout &lt;&lt; "Enter the number of cards: ";
  cin &gt;&gt; cards_in_hand;
  
  
  cout &lt;&lt; "Enter cards: ";
  cin &gt;&gt; card_value;
  
  
  for (int i = 0; i &lt; card_value.size(); i++)
  {
  
      switch (card_value[i])
      {
      case'2':
          value = 2;
          total_value = value + total_value;
          break;
      case '3':
          value = 3;
          total_value = value + total_value;
          break;
      case '4':
          value = 4;
          total_value = value + total_value;
          break;
      case '5':
          value = 5;
          total_value = value + total_value;
          break;
      case '6':
          value = 6;
          total_value = value + total_value;
          break;
      case '7': {
          value = 7;
          total_value = value + total_value;
          break; }
      case '8': {
          value = 8;
          total_value = value + total_value;
          break; }
  
      case '9':
          value = 9;
          total_value = value + total_value;
          break;
      case 't':
      case 'T':
      case 'j':
      case 'J':
      case 'q':
      case 'Q':
      case 'k':
      case 'K':
          value = 10;
          total_value = value + total_value;
          break;
      case 'a':
      case 'A': {
          if (total_value &lt;= 10)
          {
              value = 11;
          }
          else
          {
              value = 1;
          }
          total_value = total_value + value;
      }
  
          if (total_value &lt;= 21)
          {
              cout &lt;&lt; "The value of your hand is: " &lt;&lt; total_value &lt;&lt; endl;
          }
          else
              cout &lt;&lt; "YOU ARE BUSTED!\n";
      }
  
  
  }
  </code></pre>
  
  <p>When I enter a78 for cards, it works only for the first char I enter, which is 'a'. It returns only 11, but how do I make it add the 7 and 8 to get 16?
  How do I add the 7 and 8 first?</p>
  
  <p>How can I make the cin input take the three values such as a78, then add them together in the switch statement? So that it adds 7 + 8 + a which should be 1, to equal 16? </p>