Simple Blackjack/21 game in console I made a simple Blackjack/21 game in C++. It does not use any fancy graphics, just the console output. It is as simple as it can get.

#include &lt;iostream&gt;
#include &lt;cstdlib&gt;
#include &lt;ctime&gt;
#include &lt;algorithm&gt;

void printData(int pTotal, int dCard) {

    std::cout &lt;&lt; "\nYour total is " &lt;&lt; pTotal;
    std::cout &lt;&lt; "\nDealer has a " &lt;&lt; dCard &lt;&lt; " showing.\n";

}

int getCard() {

    return std::rand() % 11 + 2;

}

void turn(int&amp; pTotal, char choice, bool&amp; stay) {

    // If the user wants to hit
    if (choice == 'H' || choice == 'h') {

        // If the user hits 21 or above
        if ((pTotal += getCard()) &gt;= 21) {

            std::cout &lt;&lt; "Your total is " &lt;&lt; pTotal;
            stay = true;

        }

        return;
    }

    // Since the only other option can be to stay, then stay
    stay = true;

}

int main() {

    bool stay;
    char choice = NULL;

    while (true) {

        std::cout &lt;&lt; "================================";
        stay = false;

        // Initialize srand and get random card numbers
        std::srand(std::time(0));
        int dCard = getCard();
        int pTotal = getCard() + getCard();
        int dTotal = dCard + getCard();


        // Player's turn
        while (!stay) {

            printData(pTotal, dCard);
            std::cout &lt;&lt; "[H]it or [S]tay?\n";
            std::cin &gt;&gt; choice;
            turn(pTotal, choice, stay);

        }

        stay = false;
        std::cout &lt;&lt; "\n\nIt is now the dealer's turn!\n";

        // Dealer's turn
        while (dTotal &lt;= 21 &amp;&amp; !stay) {

            if (dTotal &gt;= 17)
                stay = true;
            else
                dTotal += getCard();

        }

        // Display winner
        std::cout &lt;&lt; "\n\nThe player has " &lt;&lt; pTotal &lt;&lt; ".\nThe dealer has " &lt;&lt; dTotal &lt;&lt; ".\n\n";
        if ((std::abs(21 - pTotal)) &lt; (std::abs(21 - dTotal))) std::cout &lt;&lt; "The player wins!\n";
        else std::cout &lt;&lt; "The dealer wins!\n";

    }

}



Is this code efficient?
Is the code easy to read/understand and to follow?
Are variable names appropriate?
I want my money back!
Your total is 15
Dealer has a 4 showing.
[H]it or [S]tay?
s


It is now the dealer's turn!


The player has 15.
The dealer has 23.   &lt;&lt;=====

The dealer wins!     &lt;&lt;=====

Your casino is cheating! Also you're not handling aces, all face cards are supposed to have a value of 10, and there are 13 ranks in a suit but your getCard function can only return 11 different values (2 to 12).
This means that you can lose right off the bat:
$ ./a.out 
================================
Your total is 24       &lt;&lt;======     :-(
Dealer has a 9 showing.
[H]it or [S]tay?


In turn, if the player enters h and doesn't bust, you're not setting stay - this happens to work given the code flow, but it looks odd. Set it before returning.
If the user enters gibberish, you always interpret that as stay. That's not user-friendly.
In main:
bool stay;
char choice = NULL;

That's not a valid initializer for a char - chars are not pointers. And leaving a variable (stay) uninitialized is not a good idea. You should move stay inside the loop, only declare it when you give it its first value. (I'd also use two separate variables for the dealer and the player.)
Remove choice from main altogether. Only turn needs it, so handle the user input in there completely. (And have turn return hit/stay so you don't need that out parameter.)
This shouldn't be inside the loop:
std::srand(std::time(0));

You should initialize the RNG only once, do that at the very start of main. C++11 introduced new random generation facilities, you should look into them.
These lines are too long:
// Display winner
std::cout &lt;&lt; &quot;\n\nThe player has &quot; &lt;&lt; pTotal &lt;&lt; &quot;.\nThe dealer has &quot; &lt;&lt; dTotal &lt;&lt; &quot;.\n\n&quot;;
if ((std::abs(21 - pTotal)) &lt; (std::abs(21 - dTotal))) std::cout &lt;&lt; &quot;The player wins!\n&quot;;
else std::cout &lt;&lt; &quot;The dealer wins!\n&quot;;

Try something like:
// Display winner
std::cout &lt;&lt; &quot;\n\nThe player has &quot; &lt;&lt; pTotal
          &lt;&lt; &quot;.\nThe dealer has &quot; &lt;&lt; dTotal &lt;&lt; &quot;.\n\n&quot;;

if ((std::abs(21 - pTotal)) &lt; (std::abs(21 - dTotal))) {
  std::cout &lt;&lt; &quot;The player wins!\n&quot;;
} else {
  std::cout &lt;&lt; &quot;The dealer wins!\n&quot;;
}

And once you fix your logic so that a bust directly ends the players turn, and a dealer bust makes the player win, you can get rid of the std::abs since both scores will be at most 21.