Thread: need help with game inC programming for the Absolute beginner

  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    12

    need help with game inC programming for the Absolute beginner

    The game is at the end of chapter 5 and it is the Trivia Game. I am using Dev-C++ and I have a problem. When I put in all the code I get an error message at the end of this code.
    Code:
    #include <stdio.h>
    
    int sportsQuestion(void);
    int geographyQuestion(void);
    void pause(int);
    
    int giResponse = 0;
    
    main()
    
    {
          do {
              
              system("clear");
              printf("\n\tTHE TRIVIA GAME\n\n");
              printf("1\tSports\n");
              printf("2\tGeography\n");
              printf("3\tQuit\n");
              printf("\n\nEnter your selection: ");
              scanf("%d", &giResponse);
              switch(giResponse) {
                                 
                                 case 1:
                                      
                                      if (sportsQuestion()==4)
                                         printf("\nCorrect!\n");
                                      else
                                          printf("\nIncorrect\n");
                                          
                                      pause(2);
                                      break;
                                      
                                 case 2:
                                      
                                      if (geograhpyQuestion()==2)
                                          printf("\nCorrect!\n");
                                      else
                                          printf("\nIncorrect\n");
                                      pause(2);
                                      break;
                                 }
              }
    }
    right at the end I get an error message that says "Syntax error before '}' token. Can anyone please help me and tell me what this error code is for?

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    do requires while
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User
    Join Date
    Dec 2006
    Posts
    12
    Quote Originally Posted by vart
    do requires while
    Now I get a [link error] Undefined reference to 'geographyQuestion'

  4. #4
    Registered User
    Join Date
    Jun 2006
    Posts
    45
    AKA
    Code:
    do { ... } while( conditional statement )
    EDIT

    Have you defined your functions? That snippet there just declares them...

  5. #5
    Registered User
    Join Date
    Dec 2006
    Posts
    12
    Quote Originally Posted by SG57
    AKA
    Code:
    do { ... } while( conditional statement )
    EDIT

    Have you defined your functions? That snippet there just declares them...
    thanks for the help but I am new and confused so forget I asked I will re-read the chapter to see what it says then if I still can't figure it out I will come back and post again but for now I am gonna go and continue to read the book. Thank you again.

  6. #6
    Registered User
    Join Date
    Dec 2006
    Posts
    12
    Quote Originally Posted by SG57
    AKA
    Code:
    do { ... } while( conditional statement )
    EDIT

    Have you defined your functions? That snippet there just declares them...
    it tells me to put
    Code:
     while ( giResponse !=3);
    in and I did but it still comes up with that error message.

  7. #7
    Registered User
    Join Date
    Dec 2006
    Posts
    12
    Quote Originally Posted by SG57
    Have you defined your functions? That snippet there just declares them...
    I just read what you said and here is the code I have for the defined function.
    Code:
    int geographyQuestion(void)
    {
        int iAnswer = 0;
        
        system("clear");
        printf("\tGeography Question\n");
        printf("\nWhat is the state capital of Florida? ");
        printf("\n\n1\tPensacola\n");
        printf("2\tTallahassee\n");
        printf("3\tJacksonville\n");
        printf("4\tMiami\n");
        printf("\nEnter your selection: ");
        scanf("%d", &iAnswer);
        
        return iAnswer;
    }
    that is what I have for the definition.

  8. #8
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    Code:
    if (geograhpyQuestion()==2)
    to

    Code:
    if (geographyQuestion()==2)
    note the spelling mistake

    ssharish2005

  9. #9
    Registered User
    Join Date
    Dec 2006
    Posts
    12
    Quote Originally Posted by ssharish2005
    Code:
    if (geograhpyQuestion()==2)
    to

    Code:
    if (geographyQuestion()==2)
    note the spelling mistake

    ssharish2005
    Thank you sooo.... much, one more thing is it doesn't recognize the clear command how would I fix that?

  10. #10
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    Using win32:
    Code:
    system("CLS");
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  11. #11
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    well, system fucntion for clear the system screen is not a good idea. I fact using a system function is itself is not a good idea.

    In you case, Clear is not portable, Cos windows dosn;t understand what is Clear command.

    On windows -> "cls"
    On *nix -> "clear"

    And i guess u are using windows so use system("cls");

    there is a note on how to clear a screen on FAQ have a go. And at the same instead of pause fucntion u can use getchar() fucntion.

    ssharish2005
    Last edited by ssharish2005; 12-04-2006 at 04:57 PM.

  12. #12
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    Since clear didn't work, I assumed he was using windows. ssharish2005 is right, though, this is nonportable and there are alternatives.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  13. #13
    Registered User
    Join Date
    Dec 2006
    Posts
    12
    Quote Originally Posted by manutd
    Using win32:
    Code:
    system("CLS");
    Ya, umm I used that code instead of what I had and the whole computer went haywire and I had to unplug the computer so that didn't work, thx for trying to help though.

  14. #14
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    What OS are you using? Under windows, that code invokes the cls program, clearing the screen.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  15. #15
    Registered User
    Join Date
    Dec 2006
    Posts
    12
    Quote Originally Posted by Boyrobber
    Ya, umm I used that code instead of what I had and the whole computer went haywire and I had to unplug the computer so that didn't work, thx for trying to help though.
    Wait sorry, I did that but I had it in a console application, thats why it went crazy, However I did it in an empty project and it worked thanks for the help it is working good. Thanks to ya'lls help I now have a pretty good flowing game.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Please comment on my c++ game
    By MegaManZZ in forum Game Programming
    Replies: 10
    Last Post: 01-22-2008, 11:03 AM
  2. Game Engine Link Prob
    By swgh in forum Game Programming
    Replies: 2
    Last Post: 01-26-2006, 12:14 AM
  3. Absolute beginner
    By cstalnak in forum Tech Board
    Replies: 19
    Last Post: 01-22-2006, 02:44 AM
  4. Game Independent Anti-cheat Project Needs Programmers
    By GIA Project Lea in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 09-15-2005, 07:41 PM
  5. Windows programming for beginner (Absolute beginner)
    By WDT in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2004, 11:21 AM