Thread: BLACKJACK - final

  1. #1
    Registered User KAUFMANN's Avatar
    Join Date
    Jan 2011
    Location
    Coimbra, Portugal
    Posts
    31

    BLACKJACK - final

    Hello there. So I've completed the code to my little blackjack code and it seems correctly written, however, I haven't been able to run the code to see how it works because of an syntax error which I have been struggling to find, but nothing turns up. I've run the code up and down and I just can't find any bug. Will you take a look at it?

    The error message reads: syntax error before "system"; line 44


    Code:
    #include<stdio.h>
    #include <time.h>
    
    int main(void){
        int n,i,k,cont,cont2;
        char card;
        
        srand(time(NULL));
        for(n=0;n<20;n++){
                          cont=0;
                          printf("#####################################\n");
                          printf("             BLACKJACK\n\n");
                          
                          do{
                             printf("Draw card??\n");
                             scanf("%c",&card);
                             
                             if(card == 's'){
                                  cont+=rand()%12;
                                  if(cont>21){
                                              printf("%d",cont);
                                              printf("You just lost!!\n");}
                                              
                                  if(cont==21){
                                               printf("BLACKJACK!!!");}
                                               
                                  else{
                                       printf("%d\n",cont);}
                                              }
                                  }while(card!='n' && cont < 22);
                             do{
                                  cont2=0;
                                  do{
                                  cont2+=rand()%12;}while(cont2<18);
                                  if(cont2>21){
                                              printf("You have won!!\n");}
                                  if(cont2==21){
                                                if(cont==cont2){
                                                                printf("Split pot!!\n");}
                                                                }
                                  if(cont2>cont && cont2<22){
                                                printf("You lost: you had %d points to %d from the Computer\n",cont,cont2);}
                                                }
                          system("pause");
                          system("cls");
                          }
        return 0;
    }
    Last edited by KAUFMANN; 03-31-2011 at 11:54 AM. Reason: Adding the error.

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    It might help if you posted the error message...

  3. #3
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Posting the error would help.

    EDIT: Beaten to the punch.
    If you understand what you're doing, you're not learning anything.

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by itsme86 View Post
    Posting the error would help.

    EDIT: Beaten to the punch.
    LOL... Great minds think alike???

  5. #5
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    One issue I see is you need to include stdlib.h in order to use srand() and system.

    Do all of your do statements have there while statement?

    Jim

  6. #6
    Registered User KAUFMANN's Avatar
    Join Date
    Jan 2011
    Location
    Coimbra, Portugal
    Posts
    31
    Quote Originally Posted by CommonTater View Post
    LOL... Great minds think alike???

    The error message reads: syntax error before "system".

    Quote Originally Posted by jimblumberg View Post
    One issue I see is you need to include stdlib.h in order to use srand() and system.

    Do all of your do statements have there while statement?

    Jim
    Oh boy. That's got to be it. I forgot to write the while statement after the last do.

    Thanks, I don't know how I missed that one.

    The program works horribly, by the way lol. Gotta go work on the code.
    Last edited by KAUFMANN; 03-31-2011 at 12:00 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Final Exam Review Question, please help
    By matthayzon89 in forum C Programming
    Replies: 166
    Last Post: 04-28-2010, 03:48 AM
  2. Simple Blackjack Program
    By saber1357 in forum C Programming
    Replies: 1
    Last Post: 03-28-2009, 03:19 PM
  3. DirectX dll Final Debug and Final Retail
    By hdragon in forum Tech Board
    Replies: 0
    Last Post: 11-15-2005, 09:46 PM
  4. Help with Blackjack program
    By sugie in forum C++ Programming
    Replies: 1
    Last Post: 04-30-2005, 12:30 AM
  5. reviewing for final exam, need help with this question
    By jlmac2001 in forum C++ Programming
    Replies: 12
    Last Post: 11-26-2003, 08:37 AM