#include %c %c “, diamond, diamond, diamond, heart,

#include #include #include #include #include #define spade 06#define club 05#define diamond 04#define heart 03#define RESULTS “Blackjack.

txt”int j;int l;int d;int won;int jt1;int jt2;int loss;int LOSS;int cash=1;int CASH=1;int bet;int BET;int randomcard;int playertotal=0;int player2=0;int dealertotal;int player2;int clubcard();int diamondcard();int heartcard();int spadecard();int randcard();int betting();void asktitle();void rules();void play();void dealer();void stay();void cash_test();void askover();void fileresults();int main(void){    char choice_1;    printf(“”);    printf(“%c%c%c%c%c     %c%c            %c%c         %c%c%c%c%c    %c    %c                “, club, club, club, club, club, spade, spade, diamond, diamond, heart, heart, heart, heart, heart, club, club);    printf(“%c    %c    %c%c           %c  %c       %c     %c   %c   %c              “, club, club, spade, spade, diamond, diamond, heart, heart, club, club);    printf(“%c    %c    %c%c          %c    %c     %c          %c  %c               “, club, club, spade, spade, diamond, diamond, heart, club, club);    printf(“%c%c%c%c%c     %c%c          %c %c%c %c     %c          %c %c              “, club, club, club, club, club, spade, spade, diamond, diamond, diamond, diamond, heart, club, club);    printf(“%c    %c    %c%c         %c %c%c%c%c %c    %c          %c%c %c             “, club, club, spade, spade, diamond, diamond, diamond, diamond, diamond, diamond, heart, club, club, club);    printf(“%c     %c   %c%c         %c      %c    %c          %c   %c               “, club, club, spade, spade, diamond, diamond, heart, club, club);    printf(“%c     %c   %c%c        %c        %c    %c     %c   %c    %c             “, club, club, spade, spade, diamond, diamond, heart, heart, club, club);    printf(“%c%c%c%c%c%c    %c%c%c%c%c%c%c   %c        %c     %c%c%c%c%c    %c     %c            “, club, club, club, club, club, club, spade, spade, spade, spade, spade, spade, spade, diamond, diamond, heart, heart, heart, heart, heart, club, club);    printf(”     %c%c%c%c%c%c%c%c      %c%c         %c%c%c%c%c    %c    %c                “, diamond, diamond, diamond, diamond, diamond, diamond, diamond, diamond, heart, heart, club, club, club, club, club, spade, spade);    printf(”        %c%c        %c  %c       %c     %c   %c   %c              “, diamond, diamond, heart, heart, club, club, spade, spade);    printf(”        %c%c       %c    %c     %c          %c  %c               “, diamond, diamond, heart, heart, club, spade, spade);    printf(”        %c%c       %c %c%c %c     %c          %c %c              “, diamond, diamond, heart, heart, heart, heart, club, spade, spade);    printf(”        %c%c      %c %c%c%c%c %c    %c          %c%c %c             “, diamond, diamond, heart, heart, heart, heart, heart, heart, club, spade, spade, spade);    printf(”        %c%c      %c      %c    %c          %c   %c               “, diamond, diamond, heart, heart, club, spade, spade);    printf(”     %c  %c%c     %c        %c    %c     %c   %c    %c             “, diamond, diamond, diamond, heart, heart, club, spade, spade,spade);    printf(”      %c%c%c      %c        %c     %c%c%c%c%c    %c     %c            “, diamond, diamond, diamond, heart, heart, club, club, club, club, club, spade, spade);    printf(“”);    printf(”      KAAYATHRI SUBRAMANIAM “);    printf(”    QIUP201710-001486 “);    asktitle();    printf(“”);    printf(“”);    system(“pause”);    return(0);}void asktitle(){    char choice_1;    int  choice_2;     printf(”                Is it true that you are Ready?”);     printf(”             ————————————“);     printf(”                           (Y/N)                        “);     scanf(“%c”,&choice_1);    while((choice_1!=’Y’) && (choice_1!=’N’) && (choice_1!=’y’) && (choice_1!=’n’))    {        printf(“”);        printf(“INVALID Choice. Please Enter Y = YES or N = NO.”);        scanf(“%c”,&choice_1);    }    if((choice_1 == ‘Y’) || (choice_1 == ‘y’))    {            system(“cls”);            printf(“Enter 1 to Begin the Greatest Game Ever Played.”);            printf(“Enter 2 to See a  List of Rules.”);            printf(“Enter 3 to Exit Game. “);            printf(“Choice: “);            scanf(“%d”, & choice_2);            if(( choice_2<1) || ( choice_2>3))            {                printf(“Incorrect Choice. Please enter 1, 2 or 3”);                scanf(“%d”, & choice_2);            }            switch( choice_2)            {                case 1:                   system(“cls”);                   play();                   break;                case 2:                   system(“cls”);                   rules();                   break;                case 3:                   printf(” HAVE A GREAT DAY.”);                   system(“pause”);                   exit(0);                   break;                default:                   printf(“Invalid Input”);            }    }    else if((choice_1 == ‘N’) || (choice_1 == ‘n’)) // If no, exit program    {        printf(“Have an almost perfect day!”);        system(“pause”);        exit(0);    }    return;}void rules(){     char choice_1;     int choice_2;     printf(”           RULES OF BLACKJACK”);     printf(”          —————————“);     printf(“I.

We Will Write a Custom Essay Specifically
For You For Only $13.90/page!


order now

“);     printf(”       Ought not scrutinize the chances of this GAME .”);     printf(”      %c This program produces cards indiscriminately “, spade);     printf(”      %c On the off chance that you continue losing, you are exceptionally unfortunate “, diamond);     printf(“II.”);     printf(”       Each card has a value.”);     printf(”      %c Number cards 1 to 10 hold an estimation of their number.

.”, spade);     printf(”      %c  J, Q, and K cards hold an estimation of 10.”, diamond);     printf(”      %c Ace cards hold a value of 11″, club);     printf(”     The objective of this GAME is to achieve a card esteem aggregate of 21.”);     printf(“III.”);     printf(”     After the overseeing of the underlying two cards, YOU ought to pick whether to HIT or STAY.

“);     printf(”      %c staying will guard you, hitting will include a card”, spade);     printf(”    Since you are contending with the merchant, you should beat his hand.”);     printf(”     Yet, BEWARE!.”);     printf(”      %c If your total goes over 21, you will LOSE!.”, diamond);     printf(”     But the world is not over, because you can always play again.

“);     printf(“%c%c%c YOUR RESULTS ARE RECORDED AND FOUND IN SAME FOLDER AS PROGRAM %c%c%c”, spade, heart, club, club, heart, spade);     printf(” Would you like to go the previous screen? (I will not take NO for an answer)”);     printf(”                  (Y/N)                    “);     scanf(“%c”,&choice_1);     while((choice_1!=’Y’) && (choice_1!=’y’) && (choice_1!=’N’) && (choice_1!=’n’))    {        printf(“”);        printf(“INVALID Choice. Please Enter Y = YES or N = NO.”);        scanf(“%c”,&choice_1);    }     while((choice_1!=’Y’) && (choice_1!=’y’) && (choice_1!=’N’) && (choice_1!=’n’))    {        printf(“”);        printf(“INVALID Choice. Please Enter Y = YES or N = NO.”);        scanf(“%c”,&choice_1);    }    if((choice_1 == ‘Y’) || (choice_1 == ‘y’))    {            system(“cls”);            asktitle();    }    else if((choice_1 == ‘N’) || (choice_1 == ‘n’))    {        system(“cls”);        printf(”                 I told you so.”);        asktitle();    }    return;} // End functionint clubcard(){    srand((unsigned) time(NULL));    j=rand()%13+1;    if(j<=9)    {    printf("-------");    printf("|%d    |", club);    printf("|  %d  |", j);    printf("|    %d|", club);    printf("-------");    }    if(j==10)    {    printf("________");    printf("|%c    |", club);    printf("|  J   |");    printf("|    %c|", club);    printf("________");    }    if(j==11)    {    printf("-------");    printf("|%c    |", club);    printf("|  A   |");    printf("|    %c|", club);    printf("-------");    if(playertotal<=10)         {             j=11;         }         else         {             j=1;         }    }    if(j==12) //If  number is 12, print card with Q (Queen) on face    {    //Club Card    printf("-------");    printf("|%c    |", club);    printf("|  Q   |");    printf("|    %c|", club);    printf("-------");    j=10; //Set card value to 10    }    if(j==13) //If  number is 13, print card with K (King) on face    {    //Club Card    printf("-------");    printf("|%c    |", club);    printf("|  K   |");    printf("|    %c|", club);    printf("-------");    j=10; //Set card value to 10    }    return j;}// End functionint diamondcard() //Displays Diamond Card Image{    srand((unsigned) time(NULL)); //Generates  seed for rand() function    j=rand()%13+1;    if(j<=9) //If  number is 9 or less, print card with that number    {    //Diamond Card    printf("-------");    printf("|%c    |", diamond);    printf("|  %d  |", j);    printf("|    %c|", diamond);    printf("-------");    }    if(j==10) //If  number is 10, print card with J (Jack) on face    {    //Diamond Card    printf("-------");    printf("|%c    |", diamond);    printf("|  J   |");    printf("|    %c|", diamond);    printf("-------");    }    if(j==11) //If random number is 11, print card with A (Ace) on face    {    //Diamond Card    printf("-------");    printf("|%c    |", diamond);    printf("|  A   |");    printf("|    %c|", diamond);    printf("-------");    if(playertotal<=10) //If  number is Ace, change value to 11 or 1 depending on dealer total         {             j=11;         }         else         {             j=1;         }    }    if(j==12) //If  number is 12, print card with Q (Queen) on face    {    //Diamond Card    printf("________");    printf("|%c    |", diamond);    printf("|  Q   |");    printf("|    %c|", diamond);    printf("________");    j=10; //Set card value to 10    }    if(j==13) //If  number is 13, print card with K (King) on face    {    //Diamond Card    printf("-------");    printf("|%c    |", diamond);    printf("|  K   |");    printf("|    %c|", diamond);    printf("-------");    j=10; //Set card value to 10    }    return j;}// End functionint heartcard() //Displays Heart Card Image{    srand((unsigned) time(NULL)); //Generates random seed for rand() function    j=rand()%13+1;    if(j<=9) //If random number is 9 or less, print card with that number    {    //Heart Card    printf("-------");    printf("|%c    |", heart);    printf("|  %d  |", j);    printf("|    %c|", heart);    printf("-------");    }    if(j==10) //If random number is 10, print card with J (Jack) on face    {    //Heart Card    printf("-------");    printf("|%c    |", heart);    printf("|  J   |");    printf("|    %c|", heart);    printf("-------");    }    if(j==11) //If random number is 11, print card with A (Ace) on face    {    //Heart Card    printf("-------");    printf("|%c    |", heart);    printf("|  A   |");    printf("|    %c|", heart);    printf("-------");    if(playertotal<=10) //If random number is Ace, change value to 11 or 1 depending on dealer total         {             j=11;         }         else         {             j=1;         }    }    if(j==12) //If random number is 12, print card with Q (Queen) on face    {    //Heart Card    printf("-------");    printf("|%c    |", heart);    printf("|  Q   |");    printf("|    %c|", heart);    printf("-------");    j=10; //Set card value to 10    }    if(j==13) //If random number is 13, print card with K (King) on face    {    //Heart Card    printf("-------");    printf("|%c    |", heart);    printf("|  K   |");    printf("|    %c|", heart);    printf("-------");    j=10; //Set card value to 10    }    return j;} // End Functionint spadecard() //Displays Spade Card Image{    srand((unsigned) time(NULL)); //Generates random seed for rand() function    j=rand()%13+1;    if(j<=9) //If random number is 9 or less, print card with that number    {    //Spade Card    printf("-------");    printf("|%c    |", spade);    printf("|  %d |", j);    printf("|    %c|", spade);    printf("-------");    }    if(j==10) //If random number is 10, print card with J (Jack) on face    {    //Spade Card    printf("-------");    printf("|%c    |", spade);    printf("|  J  |");    printf("|    %c|", spade);    printf("-------");    }    if(j==11) //If random number is 11, print card with A (Ace) on face    {    //Spade Card    printf("-------");    printf("|%c    |", spade);    printf("|  A  |");    printf("|    %c|", spade);    printf("-------");    if(playertotal<=10) //If random number is Ace, change value to 11 or 1 depending on dealer total         {             j=11;         }         else         {             j=1;         }    }    if(j==12) //If random number is 12, print card with Q (Queen) on face    {    //Spade Card    printf("-------");    printf("|%c    |", spade);    printf("|  Q  |");    printf("|    %c|", spade);    printf("-------");    j=10; //Set card value to 10    }    if(j==13) //If random number is 13, print card with K (King) on face    {    //Spade Card    printf("-------");    printf("|%c    |", spade);    printf("|  K  |");    printf("|    %c|", spade);    printf("-------");    j=10; //Set card value to 10    }    return j;} // End Functionint randcard() //Generates random card{     srand((unsigned) time(NULL)); //Generates random seed for rand() function     randomcard = rand()%4+1;     if(randomcard==1)     {         clubcard();         l=j;     }     if(randomcard==2)     {         diamondcard();         l=j;     }     if(randomcard==3)     {         heartcard();         l=j;     }     if(randomcard==4)     {         spadecard();         l=j;     }     return l;} // End Functionvoid play() //Plays game{     int p=0; // holds value of player_total     int i=1,card=0; // counter for asking user to hold or stay     char choice3;playertotal=0;player2=0;dealertotal=0;cash=CASH;     cash_test();     printf("Player 1 ");     printf("Cash: $%d",cash); //Prints amount of cash user has     randcard(); //Generates random card     playertotal = p + 1; //Computes player total     p = playertotal;     card++;     system("pause");     randcard();     playertotal=player2+l;     jt1=playertotal;     card++;     printf("Player 1 Total is %d", p); //Prints player total     dealer(); //Computes and prints dealer total     betting(); //Prompts user to enter bet amount     while(i<=21) //While loop used to keep asking user to hit or stay at most twenty-one times                  //  because there is a chance user can generate twenty-one consecutive 1's     {         if(p==21) //If user total is 21, win         {             printf("! Awesome You Win!");             won = won+1;             cash = cash+bet;             printf("You have %d Wins and %d Losses. Awesome!", won, loss);             dealertotal=0;             askover();         }         if(p>21) //If player total is over 21, loss         {             printf(“WOWWWW Buddy, You Went WAY over.

“);             loss = loss+1;             cash = cash – bet;             printf(“You have %d Wins and %d Losses. Awesome!”, won, loss);             dealertotal=0;             askover();         }         if(p<=21) //If player total is less than 21, ask to hit or stay         {             printf("Would You Like to Hit or Stay?");             scanf("%c", );             while((choice3!='H') && (choice3!='h') && (choice3!='S') && (choice3!='s')) // If invalid choice entered             {                 printf("");                 printf("Please Enter H to Hit or S to Stay.");                 scanf("%c",);             }             if((choice3=='H') || (choice3=='h')) // If Hit, continues             {                 randcard();                 playertotal = p + l;                 p = playertotal;                 card++;                 printf("Your Total is %d", p);                 dealer();                  if(dealertotal==21) //Is dealer total is 21, loss                  {                      printf("Merchant Has the Better Hand. You Lose.

“);                      loss = loss+1;                      cash = cash – bet;                      printf(“You have %d Wins and %d Losses. Awesome!”, won, loss);                      dealertotal=0;                      askover();                  }                  if(dealertotal>21) //If dealer total is over 21, win                  {                      printf(“Dealer Has Went Over!. You Win!”);                      won = won+1;                      cash = cash+bet;                      printf(“You have %d Wins and %d Losses. Awesome!”, won, loss);                      dealertotal=0;                      askover();                  }             }             if((choice3==’S’) || (choice3==’s’)) // If Stay, does not continue             {                printf(“You Have Chosen to Stay at %d.

Wise Decision!”, playertotal);                stay();             }          }             i++; //While player total and dealer total are less than 21, re-do while loop     } // End While Loop} // End Functionvoid dealer() //Function to play for dealer AI{     int z;     if(dealertotal<17)     {      srand((unsigned) time(NULL) + 1);      z=rand()%13+1;      if(z<=10)      {         d=z;      }      if(z>11)      {         d=10;      }      if(z==11)      {         if(dealertotal<=10)         {             d=11;         }         else         {             d=1;         }      }     dealertotal = dealertotal + d;     }     printf("The Dealer Has a Total of %d", dealertotal);} // End Functionvoid stay(){     dealer();     if(dealertotal>=17)     {      if(playertotal>=dealertotal)      {         printf(“Unbelievable! You Win!”);         won = won+1;         cash = cash+bet;         printf(“You have %d Wins and %d Losses. Awesome!”, won, loss);         dealertotal=0;         askover();      }      if(playertotal21)      {         printf(“Unbelievable! You Win!”);         won = won+1;         cash = cash+bet;         printf(“You have %d Wins and %d Losses. Awesome!”, won, loss);         dealertotal=0;         askover();      }     }     else     {         stay();     }} // End Functionvoid cash_test(){     if (cash <= 0)     {        printf("You Are Bankrupt. Diversion Over");        cash = 500;        askover();     }}int betting(){ printf("Enter Bet: $"); scanf("%d", ); if (bet > cash) {        printf(“You can’t wager more cash than you have.

“);        printf(“Enter Bet: “);        scanf(“%d”, );        return bet; } else return bet;} // End Functionvoid askover(){    char choice_1;     printf(“Would You Like To Play Again?”);     printf(“Please Enter Y for Yes or N for No”);     scanf(“%c”,);    while((choice_1!=’Y’) && (choice_1!=’y’) && (choice_1!=’N’) && (choice_1!=’n’))    {        printf(“”);        printf(“Incorrect Choice. Please Enter Y for Yes or N for No.”);        scanf(“%c”,);    }    if((choice_1 == ‘Y’) || (choice_1 == ‘y’))    {            system(“cls”);            play();    }    else if((choice_1 == ‘N’) || (choice_1 == ‘n’))    {        fileresults();        printf(“BYE!!!!”);        system(“pause”);        exit(0);    }    return;}void fileresults(){    FILE *fpresults;    fpresults = fopen(RESULTS, “w”);    if(fpresults == NULL)    {               printf(“Error: File Missing”);               system(“pause”);               exit(1);    }    else    {     fprintf(fpresults,” FINAL RESULTS”);     fprintf(fpresults,” ———“);     fprintf(fpresults,”You  WIN %d Times”, won);     fprintf(fpresults,”You Have Lost %d Times”, loss);     fprintf(fpresults,”Continue Playing and Set an All-Time Record!”);    }     fclose(fpresults);     return;} // End Function