Results 1 to 4 of 4

Thread: Trivia game problem

  1. #1

    Thread Starter
    Hyperactive Member GamerMax5's Avatar
    Join Date
    Nov 2004
    Location
    United States
    Posts
    388

    Question Trivia game problem

    Alright, here is my trivia game (be prepared for the lameness)

    Code:
    #include <stdio.h>
    
    /*******************************************
    FUNCTION PROTOTYPES
    *******************************************/
    int sportsQuestion(void);
    int geographyQuestion(void);
    void pause(int);
    
    /*******************************************
    GLOBAL VARIABLES
    *******************************************/
    int gintResponse = 0;
    
    main(){
       do{
          system("CLS");
          printf("\tTHE TRIVIA GAME\n\n");
          printf("1\tSports\n");
          printf("2\tGeography\n");
          printf("3\tQuit\n");
          printf("\n\nEnter your selection: ");
          scanf("%d", &gintResponse);
          switch(gintResponse){
             case 1:
                if(sportsQuestion() == 4)
                   printf("\nCorrect!\n");
                else
                   printf("\nIncorrect\n");
                pause(2);
                break;
             case 2:
               if(geographyQuestion() == 2)
                  printf("\nCorrect!\n");
               else
                  printf("\nIncorrect\n");
               pause(2);
               break;
          }
       } while(gintResponse != 3);
       system("PAUSE");
    }
    
    /*******************************************
    FUNCTION DEFINITION
    *******************************************/
    int sportsQuestion(void){
       int intAnswer = 0;
       system("CLS");
       printf("\tSports Question\n\n");
       printf("WHat University did NFL star Deon Sanders attend?\n\n");
       printf("1\tUniversity of Miami\n");
       printf("2\tCalifornia State University\n");
       printf("3\tIndiana State University\n");
       printf("4\tFlorida State University\n\n");
       printf("Enter your selection: ");
       scanf("%d", intAnswer);
       return intAnswer;
    }
    
    /*******************************************
    FUNCTION DEFINITION
    *******************************************/
    int geographyQuestion(void){
       int intAnswer = 0;
       system("CLS");
       printf("\tGeography Question\n\n");
       printf("What is the capital of Flordia?\n\n");
       printf("1\tPensacola\n");
       printf("2\tTallahassee\n");
       printf("3\tJacksonville\n");
       printf("4\tMiami\n\n");
       printf("Enter your selection: ");
       scanf("%d", intAnswer);
       return intAnswer;
    }
    
    /*******************************************
    FUNCTION DEFINITION
    *******************************************/
    void pause(int intNum){
       int intCurrentTime = 0;
       int intElapsedTime = 0;
       intCurrentTime = time(NULL);
       do{
          intElapsedTime = time(NULL);
       } while((intElapsedTime - intCurrentTime) < intNum);
    }
    I can pick the category and I can get the question to appear but when I answer the question the program crashes. I don't think it's the pause function but I'm not to sure because it could be a number of things from that point in the program. Can anyone help?

  2. #2
    Lively Member
    Join Date
    Nov 2005
    Posts
    68

    Re: Trivia game problem

    Allways flush before scan (fflush(stdin)) (this must be your problem)
    Use API Sleep instead of loop for the pause
    "bla, bla,... exists number M so for each n > M bla, bla..." Exists? Where is it? (Kronecker said...)

  3. #3

    Thread Starter
    Hyperactive Member GamerMax5's Avatar
    Join Date
    Nov 2004
    Location
    United States
    Posts
    388

    Re: Trivia game problem

    lol I'm not familiar with how to code API's in C

  4. #4
    Addicted Member SpS's Avatar
    Join Date
    Jul 2005
    Posts
    201

    Re: Trivia game problem

    Use
    Code:
    Sleep(10000);
    function of<windows.h>
    10000 is in milliseconds
    #Appreciate others by rating good posts !!

    #The Software Peter Principle is in operation when unwise developers "improve" and "generalize" the software until they themselves can no longer understand it, then the project slowly dies.

    #People who are still ignorant of their ignorance are dangerous.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width