SlideShare a Scribd company logo
1 of 14
BlackJack/Blackjack.c
// Blackjack.c : Defines the entry point for the console
application.
//
#include <Windows.h>
#include <stdlib.h>
#define CLUBS 0
#define DIAMONDS 1
#define HEARTS 2
#define SPADES 3
enum{ TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT,
NINE, TEN, JACK, QUEEN, KING, ACE };
int Deck[52];
int CurrentDealCard;
int Dealer[20], Player[20];
int DealerCards, PlayerCards;
int DealerScore, PlayerScore;
void DoShuffle()
{
int i, nextcard;
int Used[52];
/* Here we clear out Used array to zeros, which indicates
no
values have been used. */
for (i = 0; i < 52; i++) Used[i] = 0;
/* Loop through the deck of cards, there are 52 values */
for (i = 0; i < 52; i++)
{
/* Here we used a do-while. If the card has already
been used,
we need to keep generating random numbers until
we find a card
that has not been used. */
do
{
nextcard = rand() % 52; /* Value from 0 to 51 */
} while (Used[nextcard] == 1); /* This is our check */
/* Here we set to 1 so that we remember that this card
has been used */
Used[nextcard] = 1;
/* Finally, put the card in the deck. */
Deck[i] = nextcard;
}
}
void DrawCard(int rank, int suit)
{
switch (rank)
{
case TWO:
printf("Two ");
break;
case THREE:
printf("Three ");
break;
case FOUR:
printf("Four ");
break;
case FIVE:
printf("Five ");
break;
case SIX:
printf("Six ");
break;
case SEVEN:
printf("Seven ");
break;
case EIGHT:
printf("Eight ");
break;
case NINE:
printf("Nine ");
break;
case TEN:
printf("Ten ");
break;
case JACK:
printf("Jack ");
break;
case QUEEN:
printf("Queen ");
break;
case KING:
printf("King ");
break;
case ACE:
printf("Ace ");
break;
}
switch (suit)
{
case CLUBS:
printf("Clubs");
break;
case DIAMONDS:
printf("Diamonds");
break;
case HEARTS:
printf("Hearts");
break;
case SPADES:
printf("Spades");
break;
}
}
void DisplayShuffledDeck()
{
int i, suit, rank;
for (i = 0; i < 52; i++)
{
suit = Deck[i] / 13;
rank = Deck[i] % 13;
DrawCard(rank, suit);
printf("n");
}
}
void DealCards()
{
PlayerCards = DealerCards = CurrentDealCard = 0;
Player[PlayerCards++] = Deck[CurrentDealCard++];
Dealer[DealerCards++] = Deck[CurrentDealCard++];
Player[PlayerCards++] = Deck[CurrentDealCard++];
Dealer[DealerCards++] = Deck[CurrentDealCard++];
}
void DisplayDealtCards()
{
int i;
printf("nnnDealer:n");
for (i = 0; i < DealerCards; i++) DrawCard(Dealer[i] % 13,
Dealer[i] / 13), printf( " " );
printf("Dealer Score is %dnnnPlayer:n", DealerScore);
for (i = 0; i < PlayerCards; i++) DrawCard(Player[i] % 13,
Player[i] / 13), printf(" ");
printf("Player Score is %dnnn", PlayerScore);
}
void DisplayChoice()
{
printf("What would you like to do?n");
printf("1. Hitn2. Standn");
}
int GetChoice(int min, int max)
{
int choice;
do
{
printf("Make a choice from %d to %d:", min, max);
scanf("%d", &choice);
} while (choice < min || choice > max);
return(choice);
}
void CalculateScores()
{
int i, rank, suit ;
PlayerScore = 0;
for (i = 0; i < PlayerCards; i++)
{
rank = Player[i] % 13;
suit = Player[i] / 13;
if (rank >= TWO && rank <= TEN) PlayerScore += (
rank + 2 );
else if (rank >= JACK && rank <= KING)
PlayerScore += 10;
else PlayerScore += 11;
}
DealerScore = 0;
for (i = 0; i < DealerCards; i++)
{
rank = Dealer[i] % 13;
suit = Dealer[i] / 13;
if (rank >= TWO && rank <= TEN) DealerScore +=
(rank + 2);
else if (rank >= JACK && rank <= KING)
DealerScore += 10;
else DealerScore += 11;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
int choice;
srand(GetTickCount());
DoShuffle();
DealCards();
CalculateScores();
DisplayDealtCards();
DisplayChoice();
choice = GetChoice(1, 2);
if (choice == 1)
{
Player[PlayerCards++] = Deck[CurrentDealCard++];
CalculateScores();
DisplayDealtCards();
}
return 0;
}
Blackjack C Source Code

More Related Content

Similar to Blackjack C Source Code

This what Im suppose to do and this is what I have so far.In thi.pdf
This what Im suppose to do and this is what I have so far.In thi.pdfThis what Im suppose to do and this is what I have so far.In thi.pdf
This what Im suppose to do and this is what I have so far.In thi.pdfkavithaarp
 
Domain Modeling Made Functional (DevTernity 2022)
Domain Modeling Made Functional (DevTernity 2022)Domain Modeling Made Functional (DevTernity 2022)
Domain Modeling Made Functional (DevTernity 2022)Scott Wlaschin
 
Rootkit on Linux X86 v2.6
Rootkit on Linux X86 v2.6Rootkit on Linux X86 v2.6
Rootkit on Linux X86 v2.6fisher.w.y
 
NewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docx
NewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docxNewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docx
NewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docxcurwenmichaela
 
The following is my code for a connectn program. When I run my code .pdf
The following is my code for a connectn program. When I run my code .pdfThe following is my code for a connectn program. When I run my code .pdf
The following is my code for a connectn program. When I run my code .pdfeyelineoptics
 
David Kopal - Write better React with ReasonML - Codemotion Milan 2018
David Kopal - Write better React with ReasonML - Codemotion Milan 2018David Kopal - Write better React with ReasonML - Codemotion Milan 2018
David Kopal - Write better React with ReasonML - Codemotion Milan 2018Codemotion
 

Similar to Blackjack C Source Code (7)

This what Im suppose to do and this is what I have so far.In thi.pdf
This what Im suppose to do and this is what I have so far.In thi.pdfThis what Im suppose to do and this is what I have so far.In thi.pdf
This what Im suppose to do and this is what I have so far.In thi.pdf
 
Dvst
DvstDvst
Dvst
 
Domain Modeling Made Functional (DevTernity 2022)
Domain Modeling Made Functional (DevTernity 2022)Domain Modeling Made Functional (DevTernity 2022)
Domain Modeling Made Functional (DevTernity 2022)
 
Rootkit on Linux X86 v2.6
Rootkit on Linux X86 v2.6Rootkit on Linux X86 v2.6
Rootkit on Linux X86 v2.6
 
NewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docx
NewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docxNewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docx
NewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docx
 
The following is my code for a connectn program. When I run my code .pdf
The following is my code for a connectn program. When I run my code .pdfThe following is my code for a connectn program. When I run my code .pdf
The following is my code for a connectn program. When I run my code .pdf
 
David Kopal - Write better React with ReasonML - Codemotion Milan 2018
David Kopal - Write better React with ReasonML - Codemotion Milan 2018David Kopal - Write better React with ReasonML - Codemotion Milan 2018
David Kopal - Write better React with ReasonML - Codemotion Milan 2018
 

More from AASTHA76

(APA 6th Edition Formatting and St.docx
(APA 6th Edition Formatting and St.docx(APA 6th Edition Formatting and St.docx
(APA 6th Edition Formatting and St.docxAASTHA76
 
(a) Thrasymachus’ (the sophist’s) definition of Justice or Right o.docx
(a) Thrasymachus’ (the sophist’s) definition of Justice or Right o.docx(a) Thrasymachus’ (the sophist’s) definition of Justice or Right o.docx
(a) Thrasymachus’ (the sophist’s) definition of Justice or Right o.docxAASTHA76
 
(Glossary of Telemedicine and eHealth)· Teleconsultation Cons.docx
(Glossary of Telemedicine and eHealth)· Teleconsultation Cons.docx(Glossary of Telemedicine and eHealth)· Teleconsultation Cons.docx
(Glossary of Telemedicine and eHealth)· Teleconsultation Cons.docxAASTHA76
 
(Assmt 1; Week 3 paper) Using ecree Doing the paper and s.docx
(Assmt 1; Week 3 paper)  Using ecree        Doing the paper and s.docx(Assmt 1; Week 3 paper)  Using ecree        Doing the paper and s.docx
(Assmt 1; Week 3 paper) Using ecree Doing the paper and s.docxAASTHA76
 
(Image retrieved at httpswww.google.comsearchhl=en&biw=122.docx
(Image retrieved at  httpswww.google.comsearchhl=en&biw=122.docx(Image retrieved at  httpswww.google.comsearchhl=en&biw=122.docx
(Image retrieved at httpswww.google.comsearchhl=en&biw=122.docxAASTHA76
 
(Dis) Placing Culture and Cultural Space Chapter 4.docx
(Dis) Placing Culture and Cultural Space Chapter 4.docx(Dis) Placing Culture and Cultural Space Chapter 4.docx
(Dis) Placing Culture and Cultural Space Chapter 4.docxAASTHA76
 
(1) Define the time value of money.  Do you believe that the ave.docx
(1) Define the time value of money.  Do you believe that the ave.docx(1) Define the time value of money.  Do you believe that the ave.docx
(1) Define the time value of money.  Do you believe that the ave.docxAASTHA76
 
(chapter taken from Learning Power)From Social Class and t.docx
(chapter taken from Learning Power)From Social Class and t.docx(chapter taken from Learning Power)From Social Class and t.docx
(chapter taken from Learning Power)From Social Class and t.docxAASTHA76
 
(Accessible at httpswww.hatchforgood.orgexplore102nonpro.docx
(Accessible at httpswww.hatchforgood.orgexplore102nonpro.docx(Accessible at httpswww.hatchforgood.orgexplore102nonpro.docx
(Accessible at httpswww.hatchforgood.orgexplore102nonpro.docxAASTHA76
 
(a) The current ratio of a company is 61 and its acid-test ratio .docx
(a) The current ratio of a company is 61 and its acid-test ratio .docx(a) The current ratio of a company is 61 and its acid-test ratio .docx
(a) The current ratio of a company is 61 and its acid-test ratio .docxAASTHA76
 
(1) How does quantum cryptography eliminate the problem of eaves.docx
(1) How does quantum cryptography eliminate the problem of eaves.docx(1) How does quantum cryptography eliminate the problem of eaves.docx
(1) How does quantum cryptography eliminate the problem of eaves.docxAASTHA76
 
#transformation10EventTrendsfor 201910 Event.docx
#transformation10EventTrendsfor 201910 Event.docx#transformation10EventTrendsfor 201910 Event.docx
#transformation10EventTrendsfor 201910 Event.docxAASTHA76
 
$10 now and $10 when complete Use resources from the required .docx
$10 now and $10 when complete Use resources from the required .docx$10 now and $10 when complete Use resources from the required .docx
$10 now and $10 when complete Use resources from the required .docxAASTHA76
 
#MicroXplorer Configuration settings - do not modifyFile.Versio.docx
#MicroXplorer Configuration settings - do not modifyFile.Versio.docx#MicroXplorer Configuration settings - do not modifyFile.Versio.docx
#MicroXplorer Configuration settings - do not modifyFile.Versio.docxAASTHA76
 
#include string.h#include stdlib.h#include systypes.h.docx
#include string.h#include stdlib.h#include systypes.h.docx#include string.h#include stdlib.h#include systypes.h.docx
#include string.h#include stdlib.h#include systypes.h.docxAASTHA76
 
$ stated in thousands)Net Assets, Controlling Interest.docx
$ stated in thousands)Net Assets, Controlling Interest.docx$ stated in thousands)Net Assets, Controlling Interest.docx
$ stated in thousands)Net Assets, Controlling Interest.docxAASTHA76
 
#include stdio.h#include stdlib.h#include pthread.h#in.docx
#include stdio.h#include stdlib.h#include pthread.h#in.docx#include stdio.h#include stdlib.h#include pthread.h#in.docx
#include stdio.h#include stdlib.h#include pthread.h#in.docxAASTHA76
 
#include customer.h#include heap.h#include iostream.docx
#include customer.h#include heap.h#include iostream.docx#include customer.h#include heap.h#include iostream.docx
#include customer.h#include heap.h#include iostream.docxAASTHA76
 
#Assessment BriefDiploma of Business Eco.docx
#Assessment BriefDiploma of Business Eco.docx#Assessment BriefDiploma of Business Eco.docx
#Assessment BriefDiploma of Business Eco.docxAASTHA76
 
#include stdio.h#include stdint.h#include stdbool.h.docx
#include stdio.h#include stdint.h#include stdbool.h.docx#include stdio.h#include stdint.h#include stdbool.h.docx
#include stdio.h#include stdint.h#include stdbool.h.docxAASTHA76
 

More from AASTHA76 (20)

(APA 6th Edition Formatting and St.docx
(APA 6th Edition Formatting and St.docx(APA 6th Edition Formatting and St.docx
(APA 6th Edition Formatting and St.docx
 
(a) Thrasymachus’ (the sophist’s) definition of Justice or Right o.docx
(a) Thrasymachus’ (the sophist’s) definition of Justice or Right o.docx(a) Thrasymachus’ (the sophist’s) definition of Justice or Right o.docx
(a) Thrasymachus’ (the sophist’s) definition of Justice or Right o.docx
 
(Glossary of Telemedicine and eHealth)· Teleconsultation Cons.docx
(Glossary of Telemedicine and eHealth)· Teleconsultation Cons.docx(Glossary of Telemedicine and eHealth)· Teleconsultation Cons.docx
(Glossary of Telemedicine and eHealth)· Teleconsultation Cons.docx
 
(Assmt 1; Week 3 paper) Using ecree Doing the paper and s.docx
(Assmt 1; Week 3 paper)  Using ecree        Doing the paper and s.docx(Assmt 1; Week 3 paper)  Using ecree        Doing the paper and s.docx
(Assmt 1; Week 3 paper) Using ecree Doing the paper and s.docx
 
(Image retrieved at httpswww.google.comsearchhl=en&biw=122.docx
(Image retrieved at  httpswww.google.comsearchhl=en&biw=122.docx(Image retrieved at  httpswww.google.comsearchhl=en&biw=122.docx
(Image retrieved at httpswww.google.comsearchhl=en&biw=122.docx
 
(Dis) Placing Culture and Cultural Space Chapter 4.docx
(Dis) Placing Culture and Cultural Space Chapter 4.docx(Dis) Placing Culture and Cultural Space Chapter 4.docx
(Dis) Placing Culture and Cultural Space Chapter 4.docx
 
(1) Define the time value of money.  Do you believe that the ave.docx
(1) Define the time value of money.  Do you believe that the ave.docx(1) Define the time value of money.  Do you believe that the ave.docx
(1) Define the time value of money.  Do you believe that the ave.docx
 
(chapter taken from Learning Power)From Social Class and t.docx
(chapter taken from Learning Power)From Social Class and t.docx(chapter taken from Learning Power)From Social Class and t.docx
(chapter taken from Learning Power)From Social Class and t.docx
 
(Accessible at httpswww.hatchforgood.orgexplore102nonpro.docx
(Accessible at httpswww.hatchforgood.orgexplore102nonpro.docx(Accessible at httpswww.hatchforgood.orgexplore102nonpro.docx
(Accessible at httpswww.hatchforgood.orgexplore102nonpro.docx
 
(a) The current ratio of a company is 61 and its acid-test ratio .docx
(a) The current ratio of a company is 61 and its acid-test ratio .docx(a) The current ratio of a company is 61 and its acid-test ratio .docx
(a) The current ratio of a company is 61 and its acid-test ratio .docx
 
(1) How does quantum cryptography eliminate the problem of eaves.docx
(1) How does quantum cryptography eliminate the problem of eaves.docx(1) How does quantum cryptography eliminate the problem of eaves.docx
(1) How does quantum cryptography eliminate the problem of eaves.docx
 
#transformation10EventTrendsfor 201910 Event.docx
#transformation10EventTrendsfor 201910 Event.docx#transformation10EventTrendsfor 201910 Event.docx
#transformation10EventTrendsfor 201910 Event.docx
 
$10 now and $10 when complete Use resources from the required .docx
$10 now and $10 when complete Use resources from the required .docx$10 now and $10 when complete Use resources from the required .docx
$10 now and $10 when complete Use resources from the required .docx
 
#MicroXplorer Configuration settings - do not modifyFile.Versio.docx
#MicroXplorer Configuration settings - do not modifyFile.Versio.docx#MicroXplorer Configuration settings - do not modifyFile.Versio.docx
#MicroXplorer Configuration settings - do not modifyFile.Versio.docx
 
#include string.h#include stdlib.h#include systypes.h.docx
#include string.h#include stdlib.h#include systypes.h.docx#include string.h#include stdlib.h#include systypes.h.docx
#include string.h#include stdlib.h#include systypes.h.docx
 
$ stated in thousands)Net Assets, Controlling Interest.docx
$ stated in thousands)Net Assets, Controlling Interest.docx$ stated in thousands)Net Assets, Controlling Interest.docx
$ stated in thousands)Net Assets, Controlling Interest.docx
 
#include stdio.h#include stdlib.h#include pthread.h#in.docx
#include stdio.h#include stdlib.h#include pthread.h#in.docx#include stdio.h#include stdlib.h#include pthread.h#in.docx
#include stdio.h#include stdlib.h#include pthread.h#in.docx
 
#include customer.h#include heap.h#include iostream.docx
#include customer.h#include heap.h#include iostream.docx#include customer.h#include heap.h#include iostream.docx
#include customer.h#include heap.h#include iostream.docx
 
#Assessment BriefDiploma of Business Eco.docx
#Assessment BriefDiploma of Business Eco.docx#Assessment BriefDiploma of Business Eco.docx
#Assessment BriefDiploma of Business Eco.docx
 
#include stdio.h#include stdint.h#include stdbool.h.docx
#include stdio.h#include stdint.h#include stdbool.h.docx#include stdio.h#include stdint.h#include stdbool.h.docx
#include stdio.h#include stdint.h#include stdbool.h.docx
 

Recently uploaded

18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 

Recently uploaded (20)

18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 

Blackjack C Source Code

  • 1. BlackJack/Blackjack.c // Blackjack.c : Defines the entry point for the console application. // #include <Windows.h> #include <stdlib.h> #define CLUBS 0 #define DIAMONDS 1 #define HEARTS 2 #define SPADES 3 enum{ TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING, ACE }; int Deck[52]; int CurrentDealCard;
  • 2. int Dealer[20], Player[20]; int DealerCards, PlayerCards; int DealerScore, PlayerScore; void DoShuffle() { int i, nextcard; int Used[52]; /* Here we clear out Used array to zeros, which indicates no values have been used. */ for (i = 0; i < 52; i++) Used[i] = 0; /* Loop through the deck of cards, there are 52 values */ for (i = 0; i < 52; i++) { /* Here we used a do-while. If the card has already been used,
  • 3. we need to keep generating random numbers until we find a card that has not been used. */ do { nextcard = rand() % 52; /* Value from 0 to 51 */ } while (Used[nextcard] == 1); /* This is our check */ /* Here we set to 1 so that we remember that this card has been used */ Used[nextcard] = 1; /* Finally, put the card in the deck. */ Deck[i] = nextcard; } }
  • 4. void DrawCard(int rank, int suit) { switch (rank) { case TWO: printf("Two "); break; case THREE: printf("Three "); break; case FOUR: printf("Four "); break; case FIVE: printf("Five "); break; case SIX:
  • 5. printf("Six "); break; case SEVEN: printf("Seven "); break; case EIGHT: printf("Eight "); break; case NINE: printf("Nine "); break; case TEN: printf("Ten "); break; case JACK: printf("Jack "); break; case QUEEN:
  • 6. printf("Queen "); break; case KING: printf("King "); break; case ACE: printf("Ace "); break; } switch (suit) { case CLUBS: printf("Clubs"); break; case DIAMONDS: printf("Diamonds"); break;
  • 7. case HEARTS: printf("Hearts"); break; case SPADES: printf("Spades"); break; } } void DisplayShuffledDeck() { int i, suit, rank; for (i = 0; i < 52; i++) { suit = Deck[i] / 13; rank = Deck[i] % 13;
  • 8. DrawCard(rank, suit); printf("n"); } } void DealCards() { PlayerCards = DealerCards = CurrentDealCard = 0; Player[PlayerCards++] = Deck[CurrentDealCard++]; Dealer[DealerCards++] = Deck[CurrentDealCard++]; Player[PlayerCards++] = Deck[CurrentDealCard++]; Dealer[DealerCards++] = Deck[CurrentDealCard++]; } void DisplayDealtCards()
  • 9. { int i; printf("nnnDealer:n"); for (i = 0; i < DealerCards; i++) DrawCard(Dealer[i] % 13, Dealer[i] / 13), printf( " " ); printf("Dealer Score is %dnnnPlayer:n", DealerScore); for (i = 0; i < PlayerCards; i++) DrawCard(Player[i] % 13, Player[i] / 13), printf(" "); printf("Player Score is %dnnn", PlayerScore); } void DisplayChoice() { printf("What would you like to do?n"); printf("1. Hitn2. Standn"); }
  • 10. int GetChoice(int min, int max) { int choice; do { printf("Make a choice from %d to %d:", min, max); scanf("%d", &choice); } while (choice < min || choice > max); return(choice); } void CalculateScores() { int i, rank, suit ; PlayerScore = 0;
  • 11. for (i = 0; i < PlayerCards; i++) { rank = Player[i] % 13; suit = Player[i] / 13; if (rank >= TWO && rank <= TEN) PlayerScore += ( rank + 2 ); else if (rank >= JACK && rank <= KING) PlayerScore += 10; else PlayerScore += 11; } DealerScore = 0; for (i = 0; i < DealerCards; i++) { rank = Dealer[i] % 13; suit = Dealer[i] / 13;
  • 12. if (rank >= TWO && rank <= TEN) DealerScore += (rank + 2); else if (rank >= JACK && rank <= KING) DealerScore += 10; else DealerScore += 11; } } int _tmain(int argc, _TCHAR* argv[]) { int choice; srand(GetTickCount()); DoShuffle();
  • 13. DealCards(); CalculateScores(); DisplayDealtCards(); DisplayChoice(); choice = GetChoice(1, 2); if (choice == 1) { Player[PlayerCards++] = Deck[CurrentDealCard++]; CalculateScores(); DisplayDealtCards(); } return 0; }