//blackjack v3 by JoJo/omgwtfun //changes: complete overhaul, changed from python to C++, added actual cards so they arent numbers, made it so the dealer actually draws and not random numbers, #include "stdafx.h" #include #include #include #include using namespace std; int ace = 0; int crdtwo = 0; int crdthr = 0; int crdfo = 0; int crdfi = 0; int crdsx = 0; int crdsv = 0; int crdei = 0; int crdn = 0; int crdte = 0; int crdja = 0; int crdqn = 0; int crdkn = 0; int getcardnum() {return (1 + rand() % 13);} int deckcheck(int x) {     if ((x == 1) && (ace < 4))     {ace += 1; return x;}     else if ((x == 2) && (crdtwo < 4))     {crdtwo += 1; return x;}     else if ((x == 3) && (crdthr < 4))     {crdthr += 1; return x;}     else if ((x == 4) && (crdfo < 4))     {crdfo += 1; return x;}     else if ((x == 5) && (crdfi < 4))     {crdfi += 1; return x;}     else if ((x == 6) && (crdsx < 4))     {crdsx += 1; return x;}     else if ((x == 7) && (crdsv < 4))     {crdsv += 1; return x;}     else if ((x == 8) && (crdei < 4))     {crdei += 1; return x;}     else if ((x == 9) && (crdn < 4))     {crdn += 1; return x;}     else if ((x == 10) && (crdte < 4))     {crdte += 1; return x;}     else if ((x == 11) && (crdja < 4))     {crdja += 1; return x;}     else if ((x == 12) && (crdqn < 4))     {crdqn += 1; return x;}     else if ((x == 13) && (crdkn < 4))     {crdkn += 1; return x;}     else if ((ace == 4) && (crdtwo == 4) && (crdthr == 4) && (crdfo == 4) && (crdfi == 4) && (crdsx == 4) && (crdsv == 4) && (crdei == 4) && (crdn == 4) && (crdte == 4) && (crdja == 4) && (crdqn == 4) && (crdkn == 4))     {ace = 0;crdtwo = 0;crdthr = 0;crdfo = 0;crdfi = 0;crdsx = 0;crdsv = 0;crdei = 0;crdn = 0;crdte = 0;crdja = 0;crdqn = 0;crdkn = 0;}     else         return deckcheck(getcardnum()); } int draw() {return deckcheck(getcardnum());} int dlrhand = 0; int dlrbuf = 0; int dlrace = 0; string dlrdis; int drldraw() {     dlrbuf = draw();     if (dlrbuf > 10)     {         if (dlrbuf == 11){dlrdis = "Jack";}         else if (dlrbuf == 12){dlrdis = "Queen"; }         else{ dlrdis = "King"; }         return 10;     }     else if (dlrbuf == 1){dlrace += 1;dlrdis = "Ace";return 11;}     else {return dlrbuf;} } int main() {     srand(time(0));     int playagain = 1;     while (playagain == 1)     {         int hithold = 2;int hndval = 0; int hndcrd1; int hndcrd2; int hndnew = 0; int hndace = 0; string crdis1; string crdis2; string crdis3;         hndcrd1 = draw();hndcrd2 = draw();         dlrhand += drldraw();dlrhand += drldraw();         if (hndcrd1 > 10)         {             hndval += 10;             if (hndcrd1 == 11){crdis1 = "Jack";}             else if (hndcrd1 == 12){ crdis1 = "Queen";}             else{crdis1 = "King";}         }         else if (hndcrd1 == 1)         {crdis1 = "Ace";hndace += 1;hndval += 11;}         else {crdis1 = std::to_string(hndcrd1);hndval += hndcrd1;}         if (hndcrd2 > 10)         {             hndval += 10;             if (hndcrd2 == 11){crdis2 = "Jack";}             else if (hndcrd1 == 12){crdis2 = "Queen";}             else{crdis2 = "King";}         }         else if (hndcrd2 == 1)         {crdis2 = "Ace";hndace += 1;hndval += 11;}         else         {crdis2 = std::to_string(hndcrd2);hndval += hndcrd2;}         std::cout << "I have a " << crdis1 << " and a " << crdis2 << " for a total of " << std::to_string(hndval) << std::endl;         while (((hithold != 1) || (hithold != 0)) && (hndval < 21))         {             std::cout << "Type 1 to hit or 0 to hold" << std::endl;             std::cin >> hithold;             if (hithold == 0)             {break;}             else if (hithold == 1)             {                 hndnew = draw();                 if (hndnew > 10)                 {hndval += 10;                 if (hndnew == 11){crdis3 = "Jack";}                 else if (hndnew == 12){crdis3 = "Queen";}                 else{crdis3 = "King";}                 }                 else if (hndnew == 1){crdis3 = "Ace";hndace += 1;hndval += 11;}                 else {crdis3 = std::to_string(hndnew);hndval += hndnew;}                 if ((hndace > 0) && (hndval > 21)){hndace -= 1;hndval -= 10;}                 std::cout << "You got an " << crdis3 << " your new total is " << hndval << std::endl;                 hithold = 2;             }         }         std::cout << "Your final total is " << hndval << std::endl << std::endl;         if (hndval > 21){ std::wcout << "Bust, you lose" << std::endl << std::endl; }         else         {std::wcout << "The dealers total is: " << dlrhand << std::endl;             while (dlrhand < 17)             {dlrhand += drldraw();                 if ((dlrhand > 21) && (dlrace > 0)){dlrhand -= 10; dlrace -= 1;}                 std::cout << "The dealer draws a " << dlrdis << " their new total is " << dlrhand << std::endl;             }             if (dlrhand > 21){std::cout << "Dealer busts" << std::endl << "You Win!" << std::endl << std::endl;}             else if (hndval > dlrhand){std::cout << "your " << hndval << " is greater than the dealers " << dlrhand << std::endl << "You Win!" << std::endl;}             else if (hndval < dlrhand){std::cout << "your " << hndval << " is less than the dealers " << dlrhand << std::endl << "You Lose" << std::endl;}             else if (hndval == dlrhand)             {std::cout << "Both of you scored " << hndval << std::endl << "You tied" << std::endl;}         }         hndval = 0; hndace = 0; dlrace = 0; dlrhand = 0;         std::cout << "Would you like to play again? 1 for yes, 0 for no" << std::endl;         std::cin >> playagain;     }     return 0; }