C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 29th, 2012, 02:51 PM
shood1234 shood1234 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 3 shood1234 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 40 m 41 sec
Reputation Power: 0
C blackjack program help

Hey all, I'm an absolute beginner who just finished reading a C programming book. I'm now moving on to "c programming: a modern approach (2nd edition).

However, before I move on, I'm trying to get a program running that was supplied in the back of the book. It's a blackjack program, and I copied it word for word to try and better understand the concepts and see the full program in action.

Here are the three errors I keep getting from the codeblocks compiler:

In function 'dispTitle':

1)error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token

2)error: old-style parameter declarations in prototyped function definition

3)error: expected '{' at end of input


I tried my best to come up with a solution. Can anyone help me out? Here is the code below. thanks so much!

c Code:
Original - c Code
  1. /* filename: BLACKJACK.C
  2. This program plays a game of Blackjack with you.
  3. The computer is the dealer and you are the victim-er, I mean player.
  4. The dealer gets a card that you can see. The dealer then asks if
  5. you want another card by asking "Hit" or "Stand". If you choose
  6. to hit, the dealer draws or stands, and the game is played out according to the cards
  7. you and the dealer have. As the real Blackjack, the dealer stands on 17.
  8. The winner is announced only after both the player's
  9. and the dealer's hands are finished. */
  10.  
  11. /* ****************************************
  12. ANSI C standard header giles appear next */
  13.  
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <time.h>
  17. #include <ctype.h>
  18.  
  19. #define BELL '\a'
  20. #define DEALER 0
  21. #define PLAYER 1
  22.  
  23. /* Must keep two sets of totals for dealer and for player. The first set counts Aces as 1
  24. and the second counts Aces as 11. Unlike real world blackjack, this program doesnt allow
  25. aces to be 1 while others aces are 11 in the same hand */
  26. #define ACELOW 0
  27. #define ACEHIGH 1
  28. /* Only one global variable is used in this entire program. The variable
  29. holds 0, which means false initially. Once the user enters his or her
  30. name in initCardsScreen(), this variable is set to 1 (for true), so
  31. the name is never asked for again the rest of the program. */
  32.  
  33. int AskedForName = 0; /* false initialy */
  34.  
  35. /* ********************************************************
  36. This program's specific prototypes */
  37.  
  38. void dispTitle(void)
  39. void initCardsScreen(int cards [52], int playerPoints[2],
  40.                      int dealerPoint[2], int total [2],
  41.                      int * numCards);
  42. int dealCard(int * numCards, int cards[52]);
  43. void dispCard(int cardDrawn, int points [2]);
  44. void totalIt(int points [2], int total [2], int who);
  45. void dealerGetsCard(int *numCards, int cards [52],
  46.                      int dealerPoints[2]);
  47. void PlayerGetsCard(int *numCards, int cards [52],
  48.                     int playerPoints [2]);
  49. char getsAns(char mesg[]);
  50. void findWinner(int total[2]);
  51.  
  52. /* *********************************************************
  53. here is main() */
  54.  
  55. int main()
  56. {
  57.     int numCards; /*equals 52 at beginning of each game */
  58.     int cards [52], playerPoints[2], dealerPoints[2], total[2];
  59.     char ans /* for users hit/stand or yes/no response */
  60.     do
  61.         { initCardsScreen(cards, playerPoints, dealerPoints, total, &numCards);
  62.         dealerGetsCard(&numCards, cards, dealerPoints);
  63.         printf("\n"); /* prints a blank line */
  64.         PlayerGetsCard(&numCards, cards, playerPoints);
  65.         PlayerGetsCard(&numCards, cards, playerPoints);
  66.             do {
  67.                 ans = getAns("Hit or stand (H/S)? ");
  68.                 if (ans == 'H')
  69.                 {
  70.                     PlayerGetsCard(&numCards, cards, playerPoints);
  71.                 }
  72.                 } while (ans != 'S');
  73.                     totalIt(playerPoints, total, PLAYER); /* players total */
  74.             do{
  75.         dealerGetsCard(&numCards, cards, dealerPoints);
  76.         } while (dealerPoints[ACEHIGH] < 17);
  77. /* 17: dealer stops */
  78.     totalIt(dealerPoints, total, DEALER);
  79. /* Dealer's total */
  80.     findWinner(total);
  81.     ans = getAns ("\nPlay Again (Y/N)? ");
  82. } while (ans == 'Y');
  83. return;
  84.  
  85.  
  86. /* ***************************************************
  87. this function initializes the fave value of the deck
  88. of cards by putting four sets of 1-13 in the 52-card array.
  89. also clears the screen and displays a title. */
  90. void initCardsScreen(int cards[52], int playerPoints[2],
  91.                      int dealerPoints[2], int total[2],
  92.                      int *numCards)
  93. {
  94.     int sub, val = 1; /* this function's work variables */
  95.     char firstName [15]; /*Holds user's first name */
  96.     *numcards = 52; /* holds running total of number of
  97.                         cards */
  98.  
  99.     for (sub = 0; sub <= 51; sub++) { /*counts from 0 to 51 */
  100.         val = (val == 14) ? 1 : val; /*if val is 14, resest to 1 */
  101.         cards[sub] = val;
  102.         val++; }
  103.     for (sub = 0; sub <= 1; sub++) /*counts from 0 to 1 */
  104.             {
  105.             playerPoints[sub]=dealerPoints[sub]=total[sub]=0; }
  106.             dispTitle();
  107.             if (AskedForName == 0) /*name asked for only once */
  108.                 {
  109.                 printf("Ok, %s, get ready for casino action!\n\n", firstName);
  110.                 getchar(); /* discards newline. you can safely */
  111.                 /* ignore compiler warning here. */
  112.                 }
  113.             return;
  114. }
  115.  
  116. /* ***********************************************************************
  117. this function gets a card for the player and updates the player's points. */
  118. void PlayerGetsCard(int *numCards, int cards[52], int playerPoints[2])
  119. {
  120.     int newCard;
  121.     newCard = dealCard(numCards, cards);
  122.     printf("You draw: ");
  123.     dispCard(newCard, playerPoints);
  124.     }
  125.  
  126. /* **********************************************************************
  127. this function gets a card for the dealer and updates the dealer's points. */
  128. void dealerGetsCard(int *numCards, int cards[52],
  129.                     int dealerPoints[2])
  130. {
  131.     int newCard;
  132.     newCard = dealCard(numCards, cards);
  133.     printf("The dealer draws: ");
  134.     dispCard(newCard, dealerPoints);
  135.     }
  136.  
  137. /* ******************************************************************
  138. this function gets a card from the deck and stores it in either
  139. the dealer's or the player's hold of cards. */
  140.  
  141. int dealCard(int * numCards, int cards[52])
  142. {
  143.     int cardDrawn, subDraw;
  144.     time_t t; /* gets random-nnumber generator */
  145.         srand(time(&t)); /* seeds random-nnumber generator */
  146.         subDraw = (rand() % (*numCards));
  147.         cardDrawn = cards[subDraw];
  148.         cards[subDraw] = cards[*numCards -1];
  149.         (*numCards)--;
  150.     return cardDrawn;
  151.     }   
  152.  
  153. /* *****************************************************************
  154. displays the last drawn card and updates points with it. */
  155. void dispCard(int cardDrawn, int points[2])
  156. {
  157.     switch (cardDrawn) {
  158.         case(11) : printf("%s\n", "Jack");
  159.         points[ACELOW] += 10;
  160.         points[ACEHIGH] += 10;
  161.         break;
  162.         case(12) : printf("%s\n", "Queen");
  163.         points[ACELOW] += 10;
  164.         points[ACEHIGH] +=10;
  165.         break;
  166.         case(13) : printf("%s\n", "King");
  167.         points[ACELOW] += 10;
  168.         points[ACEHIGH] += 10;
  169.         break;
  170.         default : points[ACELOW] += cardDrawn;
  171.             if(cardDrawn == 1)
  172.             {
  173.             printf("%s\n", "Ace");
  174.             points[ACEHIGH] += 11;
  175.             }
  176.                 else
  177.                 {
  178.                 points[ACEHIGH] += cardDrawn;
  179.                 printf("%d\n, cardDrawn"); }
  180.                 }
  181.     return;
  182. }
  183.  
  184. /* ***********************************************************
  185. tigures the total for p[layer or dealer to see who won. this
  186. function takes into account the fact that Ace is either 1 or 11. */
  187. void totalIt(int points[2], int total[2], int who)
  188. {
  189.     /* the following routine first looks to seee if the total points counting
  190.     aces as 1 is equal to the total points counting aces as 11. if so, or
  191.     if the total points counting aces as 11 is more than 21, the program
  192.     uses the total with aces as 1 only. */
  193.     if ((points[ACELOW] == points[ACEHIGH]) ||
  194.         (points [ACESHIGH] > 21))
  195.         {
  196.             total[who] = points[ACELOW]; } /* keep all aces as 1 */
  197.  
  198.             else
  199.             {
  200.             total[who] = points[ACEHIGH]; } /* keeps all aces at it */
  201.             if (who == PLAYER) /* determines the message printed */
  202.                 {
  203.                 printf("You have a total of %d\n\n", total[PLAYER]); }
  204.                 else
  205.                     {
  206.                     printf("The house stands with a total of %d\n\n", total[DEALER]); }
  207.     return;
  208. }
  209.  
  210. /* *****************************************************************
  211. prints the winning player. */
  212. void findWinner(int total[2])
  213. {
  214.     if (total[DEALER] == 21)
  215.     { printf("The house wins.\n");
  216.       return;}
  217.         if ((total[DEALER] > 21) && (total[PLAYER] > 21))
  218.         {
  219.         printf("%s", "Nobody wins.\n");
  220.         return; }
  221.             if ((total[DEALER]>=total[PLAYER]) && (total[DEALER]<21))
  222.             {
  223.             printf("The house wins.\n");
  224.             return; }
  225.                 if ((total[PLAYER] > 21) && (total[DEALER] < 21))
  226.                 {
  227.                 printf("The house wins.\n");
  228.                 return; }
  229.         printf("%s%c", "You win!\n", BELL);
  230.         return;
  231. }
  232.  
  233. /* ******************************************************************
  234. gets the user's uppercase, single-cahracter response. */
  235. char getAns(char mesg[])
  236. {
  237.     char ans;
  238.     printf("%s", mesg); /*p rints the prompt message passed */
  239.     ans = getchar();
  240.     getchar(); /* discards newline. you can safely */
  241.     /* ignore compiler warning here. */
  242.     return toupper(ans);
  243. }
  244.  
  245. /* **********************************************************************
  246. Clears everything off the screen. */
  247. void dispTitle(void)
  248. {
  249.     int i = 0;
  250.     while (i < 25)
  251.         {
  252.         printf("\n");
  253.         i++; }
  254.  
  255.         printf("\n\n*Step right up to the Blackjack tables*\n\n");
  256.         return;
  257.     }
  258. }

Last edited by shood1234 : September 29th, 2012 at 02:56 PM. Reason: syntax hi-lighter

Reply With Quote
  #2  
Old September 29th, 2012, 03:11 PM
bdb bdb is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 156 bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 15 h 48 m 11 sec
Reputation Power: 32
You're missing a semicolon at 39;
You're missing a semicolon at line 60;
I think you mean *numCards at line 97 (mind the CAPS!);
The macro is ACEHIGH at line 195 (not ACESHIGH).

Happy Coding!

Reply With Quote
  #3  
Old September 29th, 2012, 03:22 PM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed God 2nd Plane (6000 - 6499 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 6,125 dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 3 Days 16 h 57 m 4 sec
Reputation Power: 1949
Code:
/* ********************************************************
This program's specific prototypes */
 
void dispTitle(void)
void initCardsScreen(int cards [52], int playerPoints[2],
                     int dealerPoint[2], int total [2],
                     int * numCards);

Please note that there is no semicolon at the end if the prototype for dispTitle. There needs to be.

Most compilers try to be smart and to continue trying to compile the code after having encountered an error. Often this will work, but sometimes the error is such that the compiler has an entirely wrong idea of where it is in your program, which results in a large number of errors that won't make any sense to you.

That missing semicolon appears to be an error that can cause such a chain reaction, such that the compiler might have thought that it's compiling the body of the dispTitle function. When you correct that error, a lot, if not all, of those other errors should go away.

Reply With Quote
  #4  
Old September 29th, 2012, 03:42 PM
shood1234 shood1234 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 3 shood1234 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 40 m 41 sec
Reputation Power: 0
Quote:
Originally Posted by bdb
You're missing a semicolon at 39;
You're missing a semicolon at line 60;
I think you mean *numCards at line 97 (mind the CAPS!);
The macro is ACEHIGH at line 195 (not ACESHIGH).

Happy Coding!


Thanks so much for the help bdb! I fixed the errors you mentioned. However, it is now giving me about 16 errors, saying "undefined reference to:" All of the variables such as dispTitle & initCardsScreen are being called out as this error. Any ideas?


Thanks again!

Reply With Quote
  #5  
Old September 29th, 2012, 03:58 PM
bdb bdb is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 156 bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 15 h 48 m 11 sec
Reputation Power: 32
Quote:
Originally Posted by shood1234
... it is now giving me about 16 errors, saying "undefined reference to:" ...


C is a case-sensitive language.

Make sure all your prototypes, function calls, and function definitions match! They must match in case as well as name.

I notice you have a prototype for getsAns() ... but you call and define getAns(). At the time of the call there is no defintion available.

Reply With Quote
  #6  
Old September 29th, 2012, 09:06 PM
shood1234 shood1234 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 3 shood1234 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 40 m 41 sec
Reputation Power: 0
Quote:
Originally Posted by bdb
C is a case-sensitive language.

Make sure all your prototypes, function calls, and function definitions match! They must match in case as well as name.

I notice you have a prototype for getsAns() ... but you call and define getAns(). At the time of the call there is no defintion available.


Well, I've gone through the code over and over, and it runs!

but...it runs with strange problems. The dealer is handing out random number such as (12312451231) instead of 1-12. doing some strange things..

I'm certainly learning and I appreciate everyones help!


Thanks
newest code:
c Code:
Original - c Code
  1. /* filename: BLACKJACK.C
  2. This program plays a game of Blackjack with you.
  3. The computer is the dealer and you are the victim-er, I mean player.
  4. The dealer gets a card that you can see. The dealer then asks if
  5. you want another card by asking "Hit" or "Stand". If you choose
  6. to hit, the dealer draws or stands, and the game is played out according to the cards
  7. you and the dealer have. As the real Blackjack, the dealer stands on 17.
  8. The winner is announced only after both the player's
  9. and the dealer's hands are finished. */
  10.  
  11. /* ****************************************
  12. ANSI C standard header giles appear next */
  13.  
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <time.h>
  17. #include <ctype.h>
  18.  
  19. #define BELL '\a'
  20. #define DEALER 0
  21. #define PLAYER 1
  22.  
  23. /* Must keep two sets of totals for dealer and for player. The first set counts Aces as 1
  24. and the second counts Aces as 11. Unlike real world blackjack, this program doesnt allow
  25. aces to be 1 while others aces are 11 in the same hand */
  26. #define ACELOW 0
  27. #define ACEHIGH 1
  28. /* Only one global variable is used in this entire program. The variable
  29. holds 0, which means false initially. Once the user enters his or her
  30. name in initCardsScreen(), this variable is set to 1 (for true), so
  31. the name is never asked for again the rest of the program. */
  32.  
  33. int AskedForName = 0; /* false initialy */
  34.  
  35. /* ********************************************************
  36. This program's specific prototypes */
  37.  
  38. void dispTitle(void);
  39. void initCardsScreen(int cards[52], int playerPoints[2],
  40.                      int dealerPoint[2], int total[2],
  41.                      int *numCards);
  42. int dealCard(int *numCards, int cards[52]);
  43. void dispCard(int cardDrawn, int points[2]);
  44. void totalIt(int points[2], int total[2], int who);
  45. void dealerGetsCard(int *numCards, int cards[52],
  46.                      int dealerPoints[2]);
  47. void PlayerGetsCard(int *numCards, int cards[52],
  48.                     int playerPoints[2]);
  49. char getAns(char mesg[]);
  50. void findWinner(int total[2]);
  51.  
  52. /* *********************************************************
  53. here is main() */
  54.  
  55. int main()
  56. {
  57.     int numCards; /*equals 52 at beginning of each game */
  58.     int cards[52], playerPoints[2], dealerPoints[2], total[2];
  59.     char ans; /* for users hit/stand or yes/no response */
  60.     do
  61.         { initCardsScreen (cards, playerPoints, dealerPoints, total, &numCards);
  62.         dealerGetsCard(&numCards, cards, dealerPoints);
  63.         printf("\n"); /* prints a blank line */
  64.         PlayerGetsCard(&numCards, cards, playerPoints);
  65.         PlayerGetsCard(&numCards, cards, playerPoints);
  66.             do {
  67.                 ans = getAns("Hit or stand (H/S)? ");
  68.                 if (ans == 'H')
  69.                 {
  70.                     PlayerGetsCard(&numCards, cards, playerPoints);
  71.                 }
  72.                 } while (ans != 'S');
  73.                     totalIt(playerPoints, total, PLAYER); /* players total */
  74.             do{
  75.         dealerGetsCard(&numCards, cards, dealerPoints);
  76.         } while (dealerPoints[ACEHIGH] < 17);
  77. /* 17: dealer stops */
  78.     totalIt(dealerPoints, total, DEALER);
  79. /* Dealer's total */
  80.     findWinner(total);
  81.     ans = getAns ("\nPlay Again (Y/N)? ");
  82. } while (ans == 'Y');
  83. return;
  84. }
  85.  
  86. /* ***************************************************
  87. this function initializes the fave value of the deck
  88. of cards by putting four sets of 1-13 in the 52-card array.
  89. also clears the screen and displays a title. */
  90. void initCardsScreen(int cards[52], int playerPoints[2],
  91.                      int dealerPoints[2], int total[2],
  92.                      int *numCards)
  93. {
  94.     int sub, val = 1; /* this function's work variables */
  95.     char firstName [15]; /*Holds user's first name */
  96.     *numCards = 52; /* holds running total of number of
  97.                         cards */
  98.  
  99.     for (sub = 0; sub <= 51; sub++) { /*counts from 0 to 51 */
  100.         val = (val == 14) ? 1 : val; /*if val is 14, resest to 1 */
  101.         cards[sub] = val;
  102.         val++; }
  103.     for (sub = 0; sub <= 1; sub++) /*counts from 0 to 1 */
  104.             {
  105.             playerPoints[sub]=dealerPoints[sub]=total[sub]=0; }
  106.             void dispTitle();
  107.             if (AskedForName == 0) /*name asked for only once */
  108.                 {
  109.                 printf("Ok, %s, get ready for casino action!\n\n", firstName);
  110.                 getchar(); /* discards newline. you can safely */
  111.                 /* ignore compiler warning here. */
  112.                 }
  113.             return;
  114. }
  115.  
  116. /* ***********************************************************************
  117. this function gets a card for the player and updates the player's points. */
  118. void PlayerGetsCard(int *numCards, int cards[52], int playerPoints[2])
  119. {
  120.     int newCard;
  121.     newCard = dealCard(numCards, cards);
  122.     printf("You draw: ");
  123.     dispCard(newCard, playerPoints);
  124.     }
  125.  
  126. /* **********************************************************************
  127. this function gets a card for the dealer and updates the dealer's points. */
  128. void dealerGetsCard(int *numCards, int cards[52],
  129.                     int dealerPoints[2])
  130. {
  131.     int newCard;
  132.     newCard = dealCard(numCards, cards);
  133.     printf("The dealer draws: ");
  134.     dispCard(newCard, dealerPoints);
  135.     }
  136.  
  137. /* ******************************************************************
  138. this function gets a card from the deck and stores it in either
  139. the dealer's or the player's hold of cards. */
  140.  
  141. int dealCard(int * numCards, int cards[52])
  142. {
  143.     int cardDrawn, subDraw;
  144.     time_t t; /* gets random-nnumber generator */
  145.         srand(time(&t)); /* seeds random-nnumber generator */
  146.         subDraw = (rand() % (*numCards));
  147.         cardDrawn = cards[subDraw];
  148.         cards[subDraw] = cards[*numCards -1];
  149.         (*numCards)--;
  150.     return cardDrawn;
  151.     }
  152.  
  153. /* *****************************************************************
  154. displays the last drawn card and updates points with it. */
  155. void dispCard(int cardDrawn, int points[2])
  156. {
  157.     switch (cardDrawn) {
  158.         case(11) : printf("%s\n", "Jack");
  159.         points[ACELOW] += 10;
  160.         points[ACEHIGH] += 10;
  161.         break;
  162.         case(12) : printf("%s\n", "Queen");
  163.         points[ACELOW] += 10;
  164.         points[ACEHIGH] +=10;
  165.         break;
  166.         case(13) : printf("%s\n", "King");
  167.         points[ACELOW] += 10;
  168.         points[ACEHIGH] += 10;
  169.         break;
  170.         default : points[ACELOW] += cardDrawn;
  171.             if(cardDrawn == 1)
  172.             {
  173.             printf("%s\n", "Ace");
  174.             points[ACEHIGH] += 11;
  175.             }
  176.                 else
  177.                 {
  178.                 points[ACEHIGH] += cardDrawn;
  179.                 printf("%d\n, cardDrawn"); }
  180.                 }
  181.     return;
  182. }
  183.  
  184. /* ***********************************************************
  185. tigures the total for p[layer or dealer to see who won. this
  186. function takes into account the fact that Ace is either 1 or 11. */
  187. void totalIt(int points[2], int total[2], int who)
  188. {
  189.     /* the following routine first looks to seee if the total points counting
  190.     aces as 1 is equal to the total points counting aces as 11. if so, or
  191.     if the total points counting aces as 11 is more than 21, the program
  192.     uses the total with aces as 1 only. */
  193.     if ((points[ACELOW] == points[ACEHIGH]) ||
  194.         (points [ACEHIGH] > 21))
  195.         {
  196.             total[who] = points[ACELOW]; } /* keep all aces as 1 */
  197.  
  198.             else
  199.             {
  200.             total[who] = points[ACEHIGH]; } /* keeps all aces at it */
  201.             if (who == PLAYER) /* determines the message printed */
  202.                 {
  203.                 printf("You have a total of %d\n\n", total[PLAYER]); }
  204.                 else
  205.                     {
  206.                     printf("The house stands with a total of %d\n\n", total[DEALER]); }
  207.     return;
  208. }
  209.  
  210. /* *****************************************************************
  211. prints the winning player. */
  212. void findWinner(int total[2])
  213. {
  214.     if (total[DEALER] == 21)
  215.     { printf("The house wins.\n");
  216.       return;}
  217.         if ((total[DEALER] > 21) && (total[PLAYER] > 21))
  218.         {
  219.         printf("%s", "Nobody wins.\n");
  220.         return; }
  221.             if ((total[DEALER]>=total[PLAYER]) && (total[DEALER]<21))
  222.             {
  223.             printf("The house wins.\n");
  224.             return; }
  225.                 if ((total[PLAYER] > 21) && (total[DEALER] < 21))
  226.                 {
  227.                 printf("The house wins.\n");
  228.                 return; }
  229.         printf("%s%c", "You win!\n", BELL);
  230.         return;
  231. }
  232.  
  233. /* ******************************************************************
  234. gets the user's uppercase, single-cahracter response. */
  235. char getAns(char mesg[])
  236. {
  237.     char ans;
  238.     printf("%s", mesg); /*p rints the prompt message passed */
  239.     ans = getchar();
  240.     getchar(); /* discards newline. you can safely */
  241.     /* ignore compiler warning here. */
  242.     return toupper(ans);
  243. }
  244.  
  245. /* **********************************************************************
  246. Clears everything off the screen. */
  247. void dispTitle(void)
  248. {
  249.     int i = 0;
  250.     while (i < 25)
  251.         {
  252.         printf("\n");
  253.         i++; }
  254.  
  255.         printf("\n\n*Step right up to the Blackjack tables*\n\n");
  256.         return;
  257.     }

Reply With Quote
  #7  
Old October 2nd, 2012, 07:19 PM
jakotheshadows's Avatar
jakotheshadows jakotheshadows is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2009
Posts: 149 jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 12 h 1 m 16 sec
Reputation Power: 35
Line #180
Pretty sure
printf("%d\n, cardDrawn");
is wrong.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > C blackjack program help

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap