Issues figuring out how to fix C++ Blackjack program : <p>I'm currently trying to make a simple Blackjack program that is single player and only has cards from 1-10. The issue that I'm having is that whenever I ask for a new card for the third time, it doesn't total up my cards properly. The program also doesn't restart properlyHere is an example of the output:</p>

<pre><code>Welcome to Blackjack!
Here are your first cards: 10, 2
Your total is 12.
Would you like to draw another card? (y/n)
y
You got a new card with a value of 6.
Your total is now 18.
Would you like to draw another card? (y/n)
y
You got a new card with a value of 4.
Your total is now 16.
Would you like to draw another card? (y/n)
n
Welcome to Blackjack!
Here are your first cards: 6, 4
Your total is 10.
Would you like to draw another card? (y/n)
</code></pre>

<p>I have tried using a do-while loop so that it asks for a new card whenever the total &lt; 21 but it ends up the same way. I'm at a loss at how to solve this. </p>

<pre><code>#include &lt;iostream&gt;
#include &lt;ctime&gt;
#include &lt;cstdlib&gt;
using namespace std;

int getCard(int);

int main()
{
    srand(time(0));
    int total, card1, card2, newTotal = 0;
    char choice, playAgain = 'y';

    while (playAgain == 'y')
    {
        cout &lt;&lt; "Welcome to Blackjack!\n";
        card1 = rand() % 10 + 1;
        card2 = rand() % 10 + 1;
        total = card1 + card2;
        cout &lt;&lt; "Here are your first cards: " &lt;&lt; card1 &lt;&lt; ", " &lt;&lt; card2 &lt;&lt; endl;
        cout &lt;&lt; "Your total is " &lt;&lt; total &lt;&lt; "." &lt;&lt; endl;

        cout &lt;&lt; "Would you like to draw another card? (y/n)\n";
        cin &gt;&gt; choice;

         while (choice == 'y')
         {
             newTotal = getCard(total);

             if (newTotal &gt; 21)
             {
                 cout &lt;&lt; "Bust!" &lt;&lt; endl;
                 choice = 'n';
             }

             else if (newTotal &lt; 21)
             {
                cout &lt;&lt; "Would you like to draw another card? (y/n)\n";
                cin &gt;&gt; choice;
             }
             else
             {
                 cout &lt;&lt; "Congratulations, you won!\n";
                 choice = 'n';
             }
         }
      }

    cout &lt;&lt; "Would you like to play again? (y/n)\n";
    cin &gt;&gt; playAgain;

    return 0;
}

int getCard(int total)
{ 
    int addCard, newTotal;
    addCard = rand() % 10 + 1;
    newTotal = total + addCard;
    cout &lt;&lt; "You got a new card with a value of " &lt;&lt; addCard &lt;&lt; "." &lt;&lt; 
    endl;
    cout &lt;&lt; "Your total is now " &lt;&lt; newTotal &lt;&lt; "." &lt;&lt; endl;
    return newTotal;
}
</code></pre>

<p>The program is expected to start the player off with 2 cards and then ask them if they'd like to draw another one. If they input 'y' then it would do so and retotal the cards up. If they say no, then the game just ends. If they say yes and the new cards makes the total > 21 then it returns "bust." If it makes the total become 21 then it tells the player that it wins. At the end of each game, it should ask the player if they would like to play again. </p>
