Here is alittle something I wrote for my final project for my c programming class. I wanted to see what people thought of it and feel free to use it for school. I cited a blackjack program online which can be found below to help me get started. I made a several changes so its resemblance is closer to real blackjack. Although i didn't add in side bets, double down, or any other special betting functions because time issues. Although I did:
1. Improved card graphics and rule list boarder.
2. Added a function so you cannot see dealers first card until dealers turn.
3. Fixed the seed for rand() which was creating same card repeatedly.
4. Moved the description out from the code to cut down on clutter.
5. Fixed several bugs in many of the loops.
If you have anything to add let me know I'm fairly new to programming. I'm sure there are ways to shorten my code up and other things I've missed and if nothing else perhaps it may answer questions or even help you if you find yourself in the same boat I am.
Thanks
Descriptions of each part are numbered by DXX (i.e. DOO) the corresponding code begins with /*Lxx*/ (i.e. /*L00*/)
Code:// BlackjackFMJ
// BlackjackFMJ.c
//F. Marvin
//Work Cited
//-----------
//Vladislav Shulman, Blackjack
//http://cboard.cprogramming.com/c-programming/114023-simple-blackjack-program.html
//
//----------
//C includes
//----------
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <process.h>
#define spade 06
#define club 05
#define diamond 04
#define heart 03
#define RESULTS "Blackjack.txt"
//----------------
//Global Variables
//----------------
int dealerCardOne,
dealersHand,
dealerHiddenCard,
dealerTotal,
gameBet,
gameCash = 500,
gameLoss,
gameWon,
nextCard,
nextSuite,
playerTotal = 0,
randomCard;
//-------------------
//Function Prototypes
//-------------------
void askOver(),
askTitle(),
cashTest(),
dealerBot(),
dealerFirstCard(),
fileResults(),
gameRules(),
gamePlay(),
gameStay();
int clubCard(),
diamondCard(),
gameBetting(),
heartCard(),
randCard(),
spadeCard();
/*************************************
DESCRIPTION- main
D00 Generate random seed for rand();
D01 Call askTitle to bring up startup screen;
D02 System pause;
Return;
**************************************/
int main(void)
{
/*L00*/ srand((unsigned) time(NULL));
/*L01*/ askTitle();
/*L02*/ system("pause");
return(0);
}//main
/*************************************
DESCRIPTION- askOver
D00 char choiceOne;
D01 Display ask to play again;
D02 Obtain choiceOne;
D03 While((choiceOne!='Y') && (choiceOne!='y') && (choiceOne!='N') && (choiceOne!='n'))
{
Dispay incorrect choice;
Obtain choiceOne;
}//while
D04 If (choiceOne == yes)
{
System clear;
Call gamePlay;
}//If
D05 Else If (choiceOne == no)
{
Call fileResults;
Dispay closing;
System pause;
exit;
}//Else if
Return;
**************************************/
void
askOver()
{
/*L00*/ char choiceOne;
/*L01*/ printf("Would you like to play again (please enter Y for Yes or N for No)?");
/*L02*/ scanf_s("\n%c", &choiceOne);
/*L03*/ while((choiceOne!='Y') && (choiceOne!='y') && (choiceOne!='N') && (choiceOne!='n'))
{
printf("\n\nIncorrect choice. Please enter Y for Yes or N for No:");
scanf_s("%c",&choiceOne);
}//while
/*L04*/ if((choiceOne == 'Y') || (choiceOne == 'y'))
{
system("cls");
gamePlay();
}//if
/*L05*/ else if((choiceOne == 'N') || (choiceOne == 'n'))
{
fileResults();
printf("\n\nExiting Marvin's Blackjack\n");
printf("---------------------------\n");
system("pause");
exit(0);
}//else if
return;
}//askOver
/*************************************
DESCRIPTION- askTitle
D00 char choiceOne;
int choiceTwo;
D01 Display opening;
D02 Obtain choiceOne;
D03 While((choiceOne!='Y') && (choiceOne!='y') && (choiceOne!='N') && (choiceOne!='n'))
{
Dispay incorrect choice;
Obtain choiceOne;
}//while
D04 If (choiceOne == yes)
{
System clear;
Display game choices;
Obtain choiceTwo;
D05 If((choiceTwo<1) || (choiceTwo>3)
{
Dispay incorrect choice;
Obtain choiceTwo;
}//If
D06 Switch (Choicetwo)
{
Case 1:
System clear;
Call gamePlay;
Break;
Case 2:
System clear;
Call GameRules;
Break;
Case 3:
Display exiting game;
System pause;
System exit;
Break;
Default:
Display Invalid input;
}//Switch
}//If
D07 Else If((choiceOne == 'N') || (choiceOne == 'n'))
{
Display exiting game;
System pause;
System exit;
}//Else If
Return;
**************************************/
void
askTitle()
{
/*L00*/ char choiceOne;
int choiceTwo;
/*L01*/ printf("Entering Marvin's Blackjack\n");
printf("---------------------------\n");
printf("|%c Are you ready? %c|\n", spade, spade);
printf("---------------------------\n");
printf(" (Y/N)\n ");
/*L02*/ scanf_s("\n %c",&choiceOne);
/*L03*/ while((choiceOne!='Y') && (choiceOne!='y') && (choiceOne!='N') && (choiceOne!='n'))
{
printf("\n");
printf("Incorrect choice. Please enter Y for Yes or N for No.\n");
scanf_s("%c",&choiceOne);
}
/*L04*/ if((choiceOne == 'Y') || (choiceOne == 'y'))
{
system("cls");
printf("Enter 1 to begin the greatest game ever played.\n");
printf("Enter 2 to see a complete listing of rules.\n");
printf("Enter 3 to Exit Game.\n" );
printf("Choice: ");
scanf_s("\n%d", &choiceTwo);
/*L05*/ if((choiceTwo<1) || (choiceTwo>3))
{
printf("Incorrect choice. Please enter 1, 2 or 3");
scanf_s("\n%d", &choiceTwo);
}
/*L06*/ switch(choiceTwo)
{
case 1:
system("cls");
gamePlay();
break;
case 2:
system("cls");
gameRules();
break;
case 3:
printf("Your day could have been perfect.\n");
printf("Have an almost perfect day!\n\n");
printf("Exiting Marvin's Blackjack\n");
printf("---------------------------\n");
system("pause");
exit(0);
break;
default:
printf("Invalid Input\n");
}//switch
}//if
/*L07*/ else if((choiceOne == 'N') || (choiceOne == 'n'))
{
printf("Your day could have been perfect.\n");
printf("Have an almost perfect day!\n\n");
printf("Exiting Marvin's Blackjack\n");
printf("---------------------------\n");
system("pause");
exit(0);
}//else if
return;
}//askTitle
/*************************************
DESCRIPTION- cashTest
D00 If (gameCash is less than or equal to zero)
{
Display bankrupt and game over;
Set gameCash = 500;
Call askOver;
}//If
**************************************/
void
cashTest()
{
/*L00*/ if (gameCash <= 0)
{
printf("You are bankrupt. Game Over\n");
gameCash = 500;
askOver();
}//if
}//cashTest
/*************************************
DESCRIPTION- dealerBot
D00 int moreCards;
D01 If (dealerTotal is less than 17)
{
Set moreCards = rand()%13 + 1;
D02 If(moreCards is less than or equals 10)
{
Set dealersHand to moreCards;
}//If
D03 If(moreCards is greater than 11)
{
Set dealersHand to 10;
}//If
D04 If(moreCards equals 11)
{
D05 If(moreCards less than or equal to 11)
{
Set dealerHand to 11;
}//If
D06 Else
{
Set dealersHand to 1;
}//Else
}//If
D07 Set dealerTotal to dealerTotal plus dealersHand;
}//If
D08 Display dealers visable hand;
**************************************/
void
dealerBot()
{
/*L00*/ int moreCards;
/*L01*/ if(dealerTotal < 17)
{
moreCards = rand()%13 + 1;
/*L02*/ if(moreCards <= 10)
{
dealersHand = moreCards;
}//if
/*L03*/ if(moreCards > 11)
{
dealersHand = 10;
}//if
/*L04*/ if(moreCards == 11)
{
/*L05*/ if(dealerTotal <= 10)
{
dealersHand = 11;
}//if
/*L06*/ else
{
dealersHand = 1;
}//else
}//if
/*L07*/ dealerTotal = dealerTotal + dealersHand;
}//if
/*L08*/ printf("The dealer's visible hand has a total of %d.\n\n", dealerTotal - dealerHiddenCard);
}//dealerBot
/*************************************
DESCRIPTION- dealersFirstCard
D00 int cardHolder;
D01 Set cardHolder equal to rand()%13+1;
D02 If(cardHolder is less than or equal to 10)
{
Set DealerHiddenCard to cardHolder;
}//if
D03 If(cardHolder greater than 11)
{
Set dealerHiddenCard to 10;
}//If
D04 If(cardHolder is equal to 11)
{
D05 If(dealerCardOne is less than or equal to 10)
{
Set dealerHiddenCard to 11;
}//If
D06 Else
{
Set dealerHiddenCard to 1;
}//Else
}//if
D07 Set dealerTotal to dealerCardOne plus dealerHiddenCard;
**************************************/
void
dealerFirstCard()
{
/*L00*/ int cardHolder;
/*L01*/ cardHolder = rand()%13+1;
/*L02*/ if(cardHolder <= 10)
{
dealerHiddenCard = cardHolder;
}//if
/*L03*/ if(cardHolder > 11)
{
dealerHiddenCard = 10;
}//if
/*L04*/ if(cardHolder == 11)
{
/*L05*/ if(dealerCardOne <= 10)
{
dealerHiddenCard = 11;
}//if
/*L06*/ else
{
dealerHiddenCard = 1;
}//else
}//if
/*L07*/ dealerTotal = dealerCardOne + dealerHiddenCard;
}//dealersFirstCard
/*************************************
DESCRIPTION- fileResults
D00 FILE *fpresults;
D01 fpresults = fopen(RESULTS, "w");
D02 If(fpresults is equal to NULL)
{
Display file missing;
System pause;
Exit(1);
}//If
D03 Else
{
Dispay results;
Display number of times won;
Display number of times lost;
}//Else
D04 fclose(fpresults);
Return;
**************************************/
void
fileResults()
{
/*L00*/ FILE *fpresults;
/*L01*/ fpresults = fopen(RESULTS, "w");
/*L02*/ if(fpresults == NULL)
{
printf("\nError: File Missing\n");
system("pause");
exit(1);
}//if
/*L03*/ else
{
fprintf(fpresults,"\n\t RESULTS");
fprintf(fpresults,"\n\t---------\n");
fprintf(fpresults,"\nYou Have Won %d Times\n", gameWon);
fprintf(fpresults,"\nYou Have Lost %d Times\n", gameLoss);
}//else
/*L04*/ fclose(fpresults);
return;
}//cashTest
/*************************************
DESCRIPTION- gameRules
D00 char choiceOne;
D01 Display game rules;
D02 Obtain choiceOne;
D03 While((choiceOne != 'Y') && (choiceOne != 'y') && (choiceOne != 'N') && (choiceOne != 'n'))
{
Dispay incorrect choice;
Obtain choiceOne;
}//while
D04 If (choiceOne == yes)
{
System clear;
Call askTitle;
}//If
D05 Else If (choiceOne == no)
{
System clear;
Display I told you so;
Call askTitle;
}//Else If
Return:
**************************************/
void
gameRules()
{
/*L00*/ char choiceOne;
/*L01*/ printf(" RULES of MARVIN'S BLACKJACK\n");
printf("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",
spade, spade, heart, club, club, heart, spade, spade, heart, club, club, heart, spade, spade, heart, club, club, heart, spade, spade, heart,
club, club, heart, spade, spade, heart, club, club, heart, spade, spade, heart, club, club, heart, spade,
spade, heart, club, club, heart, spade, spade, heart, club, club, heart, spade, spade, heart, club, club, heart, spade, spade, heart,
club, club, heart, spade, spade, heart, club, club, heart, spade, spade, heart, club, club, heart, spade);
printf("%c %c Thou shalt not question the odds of this game. %c\n", spade, spade, spade);
printf("%c %c This program generates cards at random. %c\n", spade, spade, spade);
printf("%c %c If you keep losing, you are very unlucky! %c\n", spade, spade, spade);
printf("%c %c Numbered cards 1 to 10 hold a value of their %c\n", spade, spade, spade);
printf("%c number. %c\n", spade, spade, spade);
printf("%c %c J, Q, and K cards hold a value of 10. %c\n", spade, spade, spade);
printf("%c %c Ace cards hold a value of 1 or 11 %c\n", spade, spade, spade);
printf("%c %c The goal of this game is to reach a card total %c\n", spade, spade, spade);
printf("%c value of 21. %c\n", spade, spade);
printf("%c %c You must place a bet after you receive your %c\n", spade, spade, spade);
printf("%c second card. %c\n", spade, spade);
printf("%c %c After the dealing of the first two cards, %c\n", spade, spade, spade);
printf("%c YOU must decide whether to HIT or STAY. %c\n", spade, spade);
printf("%c %c Staying will keep you safe, hitting will add %c\n", spade, spade, spade);
printf("%c a card. %c\n", spade, spade, spade);
printf("%c %c Because you are competing against the dealer, you %c\n", spade, spade, spade);
printf("%c must beat his hand. %c\n", spade, spade);
printf("%c %c But play wisely because you will not be able to %c\n", spade, spade, spade);
printf("%c see the dealer's first card until his turn. %c\n", spade, spade);
printf("%c %c BUT BEWARE, if your total goes over 21, you %c\n", spade, spade, spade);
printf("%c will LOSE!. %c\n", spade, spade);
printf("%c %c If your hand ties the dealers hand at the end %c\n", spade, spade, spade);
printf("%c of the round, the round ends in a push and you %c\n", spade, spade);
printf("%c will not win or lose money on your bet. %c\n", spade, spade);
printf("%c %c But the world is not over, because you can %c\n", spade, spade, spade);
printf("%c always play again until you runout of money %c\n", spade, spade);
printf("%c before starting a new game. %c\n", spade, spade);
printf("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",
spade, heart, club, club, heart, spade, spade, heart, club, club, heart, spade, spade, heart, club, club, heart, spade, spade, heart,
club, club, heart, spade, spade, heart, club, club, heart, spade, spade, heart, club, club, heart, spade,
spade, heart, club, club, heart, spade, spade, heart, club, club, heart, spade, spade, heart, club, club, heart, spade, spade, heart,
club, club, heart, spade, spade, heart, club, club, heart, spade, spade, heart, club, club, heart, spade);
printf("%c Would you like to go the start screen? (I will %c\n", spade, spade);
printf("%c not take NO for an answer) %c\n", spade, spade);
printf("%c (Y/N) %c\n", spade, spade);
printf("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",
spade, heart, club, club, heart, spade, spade, heart, club, club, heart, spade, spade, heart, club, club, heart, spade, spade, heart,
club, club, heart, spade, spade, heart, club, club, heart, spade, spade, heart, club, club, heart, spade,
spade, heart, club, club, heart, spade, spade, heart, club, club, heart, spade, spade, heart, club, club, heart, spade, spade, heart,
club, club, heart, spade, spade, heart, club, club, heart, spade, spade, heart, club, club, heart, spade);
/*L02*/ scanf_s(" %c",&choiceOne);
/*L03*/ while((choiceOne != 'Y') && (choiceOne != 'y') && (choiceOne != 'N') && (choiceOne != 'n'))
{
printf("\nIncorrect choice. Please enter Y for Yes or N for No:");
scanf_s("\n%c",&choiceOne);
}//while
/*L04*/ if((choiceOne == 'Y') || (choiceOne == 'y'))
{
system("cls");
askTitle();
}//if
/*L05*/ else if((choiceOne == 'N') || (choiceOne == 'n'))
{
system("cls");
printf("I told you so.\n");
askTitle();
}//if else
return;
}//gameRules
/*************************************
DESCRIPTION- gamePlay
D00 int gamePlayer = 0;
int cardTotal = 1;
char choiceThree;
D01 gameCash = gameCash;
D02 Call cashTest;
D03 Display cash;
D04 Call randCard;
D05 Set playerTotal to gamePlayer plus nextSuite;
D06 Set gamePlayer to playerTotal;
D07 Call dealerFirstCard;
D08 Call randCard;
D09 Set playerTotal to gamePlayer plus nextSuite;
D10 Set gamePlayer to playerTotal;
D11 Display player total;
D12 Call dealerBot;
D13 Call gameBetting;
D14 While(cardTotal less than or equal to 21)
{
D15 If(gamePlayer equals 21)
{
Display dealer flips last card;
Display dealerTotal;
Set gameWon to gameWon plus 1;
Set gameCash to gameCash plus gameBet;
Display you win;
Display wins and loses;
Set dealerTotal to 0;
Call askOver;
}//If
D16 If(gamePlayer greater than 21)
{
Display dealer flips last card;
Display dealerTotal;
Set gameLoss to gameLoss plus 1;
Set gameCash to gameCash minus gameBet;
Display you bust;
Display wins and loses;
Set dealerTotal to 0;
Call askOver;
}//If
D17 If(gamePlayer Less than or equal to 21)
{
Obtain choiceThree;
D18 While((choiceThree!='H') && (choiceThree!='h') && (choiceThree!='S') && (choiceThree!='s'))
{
Display option to hit or stay;
Obtain choiceThree);
System clear;
}//While
D19 If((choiceThree == 'H') || (choiceThree == 'h'))
{
Call randCard;
Set playerTotal to gamePlayer plus nextSuite;
Set gamePlayer to playerTotal;
Display player total
Call dealerBot;
D20 If(gamePlayer greater than 21)
{
Set gameLoss to gameLoss plus 1;
Set gameCash to gameCash minus gameBet;
Display you bust;
Display wins and loses;
Set dealerTotal to 0;
Call askOver;
}//If
D21 If(dealerTotal is equal to 21)
{
Display dealer flips last card;
Display dealerTotal;
Set gameLoss to gameLoss plus 1;
Set gameCash to gameCash minus gameBet;
Display dealer has a better hand you lose;
Display wins and loses;
Set dealerTotal to 0;
Call askOver;
}//if
D22 If(dealerTotal greater than 21)
{
Display dealer flips last card;
Display dealerTotal;
Set gameWon to gameWon plus 1;
Set gameCash to gameCash plus gameBet;
Display dealer busts you win;
Display wins and loses;
Set dealerTotal to 0;
Call askOver;
}//if
}//if
D23 If((choiceThree=='S') || (choiceThree=='s'))
{
Display you have chosen to stay at playerTotal;
Call gameStay;
}//If
}//While
D24 cardTotal++;
}//While
**************************************/
void
gamePlay()
{
/*L00*/ int gamePlayer = 0;
int cardTotal = 1;
char choiceThree;
/*L01*/ gameCash = gameCash;
/*L02*/ cashTest();
/*L03*/ printf("Cash: $%d", gameCash);
/*L04*/ randCard();
/*L05*/ playerTotal = gamePlayer + nextSuite;
/*L06*/ gamePlayer = playerTotal;
/*L07*/ dealerFirstCard();
/*L08*/ randCard();
/*L09*/ playerTotal = gamePlayer + nextSuite;
/*L10*/ gamePlayer = playerTotal;
/*L11*/ printf("Your total is %d.\n", gamePlayer);
/*L12*/ dealerBot();
/*L13*/ gameBetting();
/*L14*/ while(cardTotal <= 21)
{
/*L15*/ if(gamePlayer == 21)
{
printf("The dealer flips his last card over and...\n");
printf("The dealer has a total of %d.\n\n", dealerTotal);
gameWon = gameWon + 1;
gameCash = gameCash + gameBet;
printf("You Win!\n");
printf("You have %d wins and %d losses.\n", gameWon, gameLoss);
dealerTotal = 0;
askOver();
}//if
/*L16*/ if(gamePlayer > 21)
{
printf("The dealer flips his last card over and...\n");
printf("The dealer has a total of %d.\n\n", dealerTotal);
gameLoss = gameLoss + 1;
gameCash = gameCash - gameBet;
printf("You bust. You lose.\n");
printf("You have %d wins and %d losses.\n\n", gameWon, gameLoss);
dealerTotal = 0;
askOver();
}//if
/*L17*/ if(gamePlayer <= 21)
{
scanf_s("%c",&choiceThree);
/*L18*/ while((choiceThree!='H') && (choiceThree!='h') && (choiceThree!='S') && (choiceThree!='s'))
{
printf("Would you like to Hit or Stay (please enter H to Hit or S to stay)?");
scanf_s("%c",&choiceThree);
system("cls");
}//while
/*L19*/ if((choiceThree == 'H') || (choiceThree == 'h'))
{
randCard();
playerTotal = gamePlayer + nextSuite;
gamePlayer = playerTotal;
printf("Your Total is %d.\n", gamePlayer);
dealerBot();
/*L20*/ if(gamePlayer > 21)
{
gameLoss = gameLoss + 1;
gameCash = gameCash - gameBet;
printf("You bust. You lose.\n");
printf("You have %d wins and %d losses.\n\n", gameWon, gameLoss);
dealerTotal = 0;
askOver();
}//if
/*L21*/ if(dealerTotal == 21)
{
printf("The dealer flips his last card over and...\n");
printf("The dealer has a total of %d.\n\n", dealerTotal);
gameLoss = gameLoss + 1;
gameCash = gameCash - gameBet;
printf("Dealer has the better hand. You lose.\n");
printf("You have %d wins and %d losses.\n\n", gameWon, gameLoss);
dealerTotal = 0;
askOver();
}//if
/*L22*/ if(dealerTotal > 21)
{
printf("The dealer flips his last card over and...\n");
printf("The dealer has a total of %d and busts.\n\n", dealerTotal);
gameWon = gameWon + 1;
gameCash = gameCash + gameBet;
printf("Dealer has went over! You Win!\n");
printf("You have %d wins and %d losses.\n\n", gameWon, gameLoss);
dealerTotal = 0;
askOver();
}//if
}//if
/*L23*/ if((choiceThree=='S') || (choiceThree=='s'))
{
printf("You have chosen to stay at %d.\n", playerTotal);
gameStay();
}//if
}//while
/*L24*/ cardTotal++;
}//while
}//gamePlay
/*************************************
DESCRIPTION- gameStay
D00 Call dealerBot;
D01 If(dealerTotal greater than or equal to 17)
{
D02 If(playerTotal greater than dealerTotal)
{
Display dealer flips last card;
Display dealerTotal;
Set gameWon to gameWon plus 1;
Set gameCash to gameCash plus gameBet;
Display you win;
Display wins and loses;
Set dealerTotal to 0;
Call askOver;
}//If
D03 If(playerTotal equals dealerTotal)
{
Display dealer flips last card;
Display dealerTotal;
Set gameWon to gameWon plus 0;
Set gameCash to gameCash plus 0;
Display round ends in a push;
Display wins and loses;
Set dealerTotal to 0;
Call askOver();
}//If
D04 If((playerTotal is less than dealerTotal) && (dealerTotal less than 21))
{
Display dealer flips last card;
Display dealerTotal;
Set gameLoss to gameLoss plus 1;
Set gameCash to gameCash minus gameBet;
Display dealer has a better hand you lose;
Display wins and loses;
Set dealerTotal to 0;
Call askOver;
}//If
D05 If(dealerTotal greater than 21)
{
Display dealer flips last card;
Display dealerTotal;
Set gameWon to gameWon plus 1;
Set gameCash to gameCash plus gameBet;
Display dealer busts you win;
Display wins and loses;
Set dealerTotal to 0;
Call askOver;
}//If
}//If
D06 Else
{
Call gameStay;
}//Else
**************************************/
void
gameStay()
{
/*L00*/ dealerBot();
/*L01*/ if(dealerTotal >= 17)
{
/*L02*/ if(playerTotal > dealerTotal)
{
printf("The dealer flips his last card over and...\n");
printf("The dealer has a total of %d.\n\n", dealerTotal);
gameWon = gameWon + 1;
gameCash = gameCash + gameBet;
printf("You Win!\n");
printf("You have %d wins and %d losses.\n\n", gameWon, gameLoss);
dealerTotal = 0;
askOver();
}//if
/*L03*/ if(playerTotal == dealerTotal)
{
printf("The dealer flips his last card over and...\n");
printf("The dealer has a total of %d.\n\n", dealerTotal);
gameWon = gameWon + 0;
gameCash = gameCash + 0;
printf("The round ends in a push!\n");
printf("You have %d wins and %d losses.\n\n", gameWon, gameLoss);
dealerTotal = 0;
askOver();
}//if
/*L04*/ if((playerTotal < dealerTotal) && (dealerTotal < 21))
{
printf("The dealer flips his last card over and...\n");
printf("The Dealer Has a Total of %d.\n\n", dealerTotal);
gameLoss = gameLoss + 1;
gameCash = gameCash - gameBet;
printf("Dealer has the better hand. You lose.\n");
printf("You have %d wins and %d losses.\n\n", gameWon, gameLoss);
dealerTotal = 0;
askOver();
}//if
/*L05*/ if(dealerTotal > 21)
{
printf("The dealer flips his last card over and...\n");
printf("The dealer has a total of %d and busts.\n\n", dealerTotal);
gameWon = gameWon + 1;
gameCash = gameCash + gameBet;
printf("The dealer went over. You Win!\n");
printf("You have %d wins and %d losses.\n\n", gameWon, gameLoss);
dealerTotal = 0;
askOver();
}//if
}//if
/*L06*/ else
{
gameStay();
}//else
}//gameStay
/*************************************
DESCRIPTION- clubCard
D00 Set nextCard to rand()%13 + 1;
D01 If(nextCard is less than or equal to 9)
{
Display number card;
}//If
D02 If(nextCard is equal to 10)
{
Display jack;
}//If
D03 If(nextCard is equal to 11)
{
Display ace;
D04 If (playerTotal greater than 11)
{
Set nextCard to 1;
}//If
D05 Else
{
Set nextCard to 11;
}//Else
}//If
D06 If(nextCard is equal to 12)
{
Display queen;
Set nextCard to 10;
}//if
D07 If(nextCard is equal to 13)
{
Display king;
Set nextCard to 10;
}//If
Return nextCard;
**************************************/
int
clubCard()
{
/*L00*/ nextCard = rand()%13 + 1;
/*L01*/ if(nextCard <= 9)
{
printf("\n%c%c%c%c%c%c%c\n", 218,196,196,196,196, 196,191);
printf("%c%c %c\n", 179, club, 179);
printf("%c %d %c\n", 179, nextCard, 179);
printf("%c %c%c\n", 179, club, 179);
printf("%c%c%c%c%c%c%c\n\n", 192,196,196,196,196, 196,217);
}//if
/*L02*/ if(nextCard == 10)
{
printf("\n%c%c%c%c%c%c%c\n", 218,196,196,196,196, 196,191);
printf("%c%c %c\n", 179, club, 179);
printf("%c J %c\n", 179, 179);
printf("%c %c%c\n", 179, club, 179);
printf("%c%c%c%c%c%c%c\n\n", 192,196,196,196,196, 196,217);
}//if
/*L03*/ if(nextCard == 11)
{
printf("\n%c%c%c%c%c%c%c\n", 218,196,196,196,196, 196,191);
printf("%c%c %c\n", 179, club, 179);
printf("%c A %c\n", 179, 179);
printf("%c %c%c\n", 179, club, 179);
printf("%c%c%c%c%c%c%c\n\n", 192,196,196,196,196, 196,217);
/*L04*/ if (playerTotal > 11)
{
nextCard = 1;
}//if
/*L05*/ else
{
nextCard = 11;
}//else
}//if
/*L06*/ if(nextCard == 12)
{
printf("\n%c%c%c%c%c%c%c\n", 218,196,196,196,196, 196,191);
printf("%c%c %c\n", 179, club, 179);
printf("%c Q %c\n", 179, 179);
printf("%c %c%c\n", 179, club, 179);
printf("%c%c%c%c%c%c%c\n\n", 192,196,196,196,196, 196,217);
nextCard = 10;
}//if
/*L07*/if(nextCard == 13)
{
printf("\n%c%c%c%c%c%c%c\n", 218,196,196,196,196, 196,191);
printf("%c%c %c\n", 179, club, 179);
printf("%c K %c\n", 179, 179);
printf("%c %c%c\n", 179, club, 179);
printf("%c%c%c%c%c%c%c\n\n", 192,196,196,196,196, 196,217);
nextCard = 10;
}//if
return nextCard;
}//clubCard
/*************************************
DESCRIPTION- diamondCard
D00 Set nextCard to rand()%13 + 1;
D01 If(nextCard is less than or equal to 9)
{
Display number card;
}//If
D02 If(nextCard is equal to 10)
{
Display jack;
}//If
D03 If(nextCard is equal to 11)
{
Display ace;
D04 If (playerTotal greater than 11)
{
Set nextCard to 1;
}//If
D05 Else
{
Set nextCard to 11;
}//Else
}//If
D06 If(nextCard is equal to 12)
{
Display queen;
Set nextCard to 10;
}//if
D07 If(nextCard is equal to 13)
{
Display king;
Set nextCard to 10;
}//If
Return nextCard;
**************************************/
int
diamondCard()
{
/*L00*/ nextCard = rand()%13 + 1;
/*L01*/ if(nextCard <= 9)
{
printf("\n%c%c%c%c%c%c%c\n", 218,196,196,196,196, 196,191);
printf("%c%c %c\n", 179, diamond, 179);
printf("%c %d %c\n", 179, nextCard, 179);
printf("%c %c%c\n", 179, diamond, 179);
printf("%c%c%c%c%c%c%c\n\n", 192,196,196,196,196, 196,217);
}//if
/*L02*/ if(nextCard == 10)
{
printf("\n%c%c%c%c%c%c%c\n", 218,196,196,196,196, 196,191);
printf("%c%c %c\n", 179, diamond, 179);
printf("%c J %c\n", 179, 179);
printf("%c %c%c\n", 179, diamond, 179);
printf("%c%c%c%c%c%c%c\n\n", 192,196,196,196,196, 196,217);
}//if
/*L03*/ if(nextCard == 11)
{
printf("\n%c%c%c%c%c%c%c\n", 218,196,196,196,196, 196,191);
printf("%c%c %c\n", 179, diamond, 179);
printf("%c A %c\n", 179, 179);
printf("%c %c%c\n", 179, diamond, 179);
printf("%c%c%c%c%c%c%c\n\n", 192,196,196,196,196, 196,217);
/*L04*/ if (playerTotal > 11)
{
nextCard = 1;
}//if
/*L05*/ else
{
nextCard = 11;
}//else
}//if
/*L06*/ if(nextCard == 12)
{
printf("\n%c%c%c%c%c%c%c\n", 218,196,196,196,196, 196,191);
printf("%c%c %c\n", 179, diamond, 179);
printf("%c Q %c\n", 179, 179);
printf("%c %c%c\n", 179, diamond, 179);
printf("%c%c%c%c%c%c%c\n\n", 192,196,196,196,196, 196,217);
nextCard = 10;
}//if
/*L07*/ if(nextCard == 13)
{
printf("\n%c%c%c%c%c%c%c\n", 218,196,196,196,196, 196,191);
printf("%c%c %c\n", 179, diamond, 179);
printf("%c K %c\n", 179, 179);
printf("%c %c%c\n", 179, diamond, 179);
printf("%c%c%c%c%c%c%c\n\n", 192,196,196,196,196, 196,217);
nextCard = 10;
}//if
return nextCard;
}//diamondCard
/*************************************
DESCRIPTION- gameBetting
D00 Display enter bet;
D01 Obtain bet;
D02 If (gameBet > gameCash)
{
Display error;
Display enter bet;
Obtain bet;
Return gameBet;
}//If
D03 Else
{
Return gameBet;
}//Else
**************************************/
int
gameBetting()
{
/*L00*/ printf("Enter bet: $");
/*L01*/ scanf_s("\n%d", &gameBet);
/*L02*/ if (gameBet > gameCash)
{
printf("You cannot bet more money than you have.\n");
printf("Enter Bet: ");
scanf_s("\n%d", &gameBet);
return gameBet;
}//if
/*L03*/ else
{
return gameBet;
}//else
}//gameBetting
/*************************************
DESCRIPTION- heartCard
D00 Set nextCard to rand()%13 + 1;
D01 If(nextCard is less than or equal to 9)
{
Display number card;
}//If
D02 If(nextCard is equal to 10)
{
Display jack;
}//If
D03 If(nextCard is equal to 11)
{
Display ace;
D04 If (playerTotal greater than 11)
{
Set nextCard to 1;
}//If
D05 Else
{
Set nextCard to 11;
}//Else
}//If
D06 If(nextCard is equal to 12)
{
Display queen;
Set nextCard to 10;
}//if
D07 If(nextCard is equal to 13)
{
Display king;
Set nextCard to 10;
}//If
Return nextCard;
**************************************/
int
heartCard()
{
/*L00*/nextCard = rand()%13 + 1;
/*L01*/ if(nextCard <= 9)
{
printf("\n%c%c%c%c%c%c%c\n", 218,196,196,196,196, 196,191);
printf("%c%c %c\n", 179, heart, 179);
printf("%c %d %c\n", 179, nextCard, 179);
printf("%c %c%c\n", 179, heart, 179);
printf("%c%c%c%c%c%c%c\n\n", 192,196,196,196,196, 196,217);
}//if
/*L02*/ if(nextCard == 10)
{
printf("\n%c%c%c%c%c%c%c\n", 218,196,196,196,196, 196,191);
printf("%c%c %c\n", 179, heart, 179);
printf("%c J %c\n", 179, 179);
printf("%c %c%c\n", 179, heart, 179);
printf("%c%c%c%c%c%c%c\n\n", 192,196,196,196,196, 196,217);
}//if
/*L03*/ if(nextCard == 11)
{
printf("\n%c%c%c%c%c%c%c\n", 218,196,196,196,196, 196,191);
printf("%c%c %c\n", 179, heart, 179);
printf("%c A %c\n", 179, 179);
printf("%c %c%c\n", 179, heart, 179);
printf("%c%c%c%c%c%c%c\n\n", 192,196,196,196,196, 196,217);
/*L04*/ if (playerTotal > 11)
{
nextCard = 1;
}//if
/*L05*/ else
{
nextCard = 11;
}//else
}//if
/*L06*/ if(nextCard == 12)
{
printf("\n%c%c%c%c%c%c%c\n", 218,196,196,196,196, 196,191);
printf("%c%c %c\n", 179, heart, 179);
printf("%c Q %c\n", 179, 179);
printf("%c %c%c\n", 179, heart, 179);
printf("%c%c%c%c%c%c%c\n\n", 192,196,196,196,196, 196,217);
nextCard = 10;
}//if
/*L07*/ if(nextCard == 13)
{
printf("\n%c%c%c%c%c%c%c\n", 218,196,196,196,196, 196,191);
printf("%c%c %c\n", 179, heart, 179);
printf("%c K %c\n", 179, 179);
printf("%c %c%c\n", 179, heart, 179);
printf("%c%c%c%c%c%c%c\n\n", 192,196,196,196,196, 196,217);
nextCard = 10;
}//if
return nextCard;
}//heartCard
/*************************************
DESCRIPTION- randCard
D00 Set randomCard to rand()%4 + 1;
D01 If(randomCard equals 1)
{
Call clubCard;
Set nextSuite to nextCard;
}//If
D02 If(randomCard equals 2)
{
Call diamondCard;
Set nextSuite to nextCard;
}//If
D03 If(randomCard equals 3)
{
Call heartCard;
Set nextSuite to nextCard;
}//If
D04 If(randomCard == 4)
{
Call spadeCard;
Set nextSuite to nextCard;
}//If
Return nextSuite;
**************************************/
int
randCard()
{
/*L00*/ randomCard = rand()%4 + 1;
/*L01*/ if(randomCard == 1)
{
clubCard();
nextSuite = nextCard;
}//if
/*L02*/ if(randomCard == 2)
{
diamondCard();
nextSuite = nextCard;
}//if
/*L03*/ if(randomCard == 3)
{
heartCard();
nextSuite = nextCard;
}//if
/*L04*/ if(randomCard == 4)
{
spadeCard();
nextSuite = nextCard;
}//if
return nextSuite;
}//randCard
/*************************************
DESCRIPTION- spadeCard
D00 Set nextCard to rand()%13 + 1;
D01 If(nextCard is less than or equal to 9)
{
Display number card;
}//If
D02 If(nextCard is equal to 10)
{
Display jack;
}//If
D03 If(nextCard is equal to 11)
{
Display ace;
D04 If (playerTotal greater than 11)
{
Set nextCard to 1;
}//If
D05 Else
{
Set nextCard to 11;
}//Else
}//If
D06 If(nextCard is equal to 12)
{
Display queen;
Set nextCard to 10;
}//if
D07 If(nextCard is equal to 13)
{
Display king;
Set nextCard to 10;
}//If
Return nextCard;
**************************************/
int
spadeCard()
{
/*L00*/ nextCard = rand()%13 + 1;
/*L01*/ if(nextCard <= 9)
{
printf("\n%c%c%c%c%c%c%c\n", 218,196,196,196,196, 196,191);
printf("%c%c %c\n", 179, spade, 179);
printf("%c %d %c\n", 179, nextCard, 179);
printf("%c %c%c\n", 179, spade, 179);
printf("%c%c%c%c%c%c%c\n\n", 192,196,196,196,196, 196,217);
}//if
/*L02*/ if(nextCard == 10)
{
printf("\n%c%c%c%c%c%c%c\n", 218,196,196,196,196, 196,191);
printf("%c%c %c\n", 179, spade, 179);
printf("%c J %c\n", 179, 179);
printf("%c %c%c\n", 179, spade, 179);
printf("%c%c%c%c%c%c%c\n\n", 192,196,196,196,196, 196,217);
}//if
/*L03*/ if(nextCard == 11)
{
printf("\n%c%c%c%c%c%c%c\n", 218,196,196,196,196, 196,191);
printf("%c%c %c\n", 179, spade, 179);
printf("%c A %c\n", 179, 179);
printf("%c %c%c\n", 179, spade, 179);
printf("%c%c%c%c%c%c%c\n\n", 192,196,196,196,196, 196,217);
/*L04*/ if (playerTotal > 11)
{
nextCard = 1;
}//if
/*L05*/ else
{
nextCard = 11;
}//else
}//if
/*L06*/ if(nextCard == 12)
{
printf("\n%c%c%c%c%c%c%c\n", 218,196,196,196,196, 196,191);
printf("%c%c %c\n", 179, spade, 179);
printf("%c Q %c\n", 179, 179);
printf("%c %c%c\n", 179, spade, 179);
printf("%c%c%c%c%c%c%c\n\n", 192,196,196,196,196, 196,217);
nextCard = 10;
}//if
/*L07*/ if(nextCard == 13)
{
printf("\n%c%c%c%c%c%c%c\n", 218,196,196,196,196, 196,191);
printf("%c%c %c\n", 179, spade, 179);
printf("%c K %c\n", 179, 179);
printf("%c %c%c\n", 179, spade, 179);
printf("%c%c%c%c%c%c%c\n\n", 192,196,196,196,196, 196,217);
nextCard = 10;
}//if
return nextCard;
}//spadeCard
//BlackjackFMJ.c