#include #include #include #include #include #define spade 06#define

#include #include #include #include #include #define spade 06#define club 05#define diamond 04#define heart 03#define RESULTS “Blackjack.txt”int k;int l;int d;int won;int loss;int cash=500;int bet;int randomcard;int playertotal=0;int dealertotal;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(”               KAAYATHRI SUBRAMANIAM “);    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(”
“);    asktitle();    printf(”
“);    printf(”
“);    system(“pause”);    return(0);}void asktitle(){    char choice_1;    int  choice_2;     printf(”
                 Are You 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 for Yes or N for 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 Complete Listing of Rules.”);            printf(”
Enter 3 to Exit Game. (Not Recommended)”);            printf(”
Choice: “);            scanf(“%d”, & choice_2);            if(( choice_23))            {                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.”);                   printf(”
Have an almost perfect day!

“);                   system(“pause”);                   exit(0);                   break;                default:                   printf(”
Invalid Input”);            }    }    else if((choice_1 == ‘N’) || (choice_1 == ‘n’)) // If no, exit program    {        printf(”
Your day could have been perfect.”);        printf(”
Have an almost perfect day!

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


order now

“);        system(“pause”);        exit(0);    }    return;}void rules(){     char choice_1;     int   choice_2;     printf(”
           RULES OF BLACKJACK”);     printf(”
          —————————“);     printf(”
I.”);     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 managing of the initial two cards, YOU should choose whether to HIT or STAY.”);     printf(”
      %c taying will guard you, hitting will include a card”, spade);     printf(”
     Because you are competing against the dealer, you must beat his hand.”);     printf(”
     BUT 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 for Yes or N for 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 for Yes or N for 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));    k=rand()%13+1;    if(k21) //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(p21) //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(dealertotal11)      {         d=10;      }      if(z==11)      {         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 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

Comments are closed.