-
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?
-
Re: Trivia game problem
Allways flush before scan (fflush(stdin)) (this must be your problem)
Use API Sleep instead of loop for the pause
-
Re: Trivia game problem
lol I'm not familiar with how to code API's in C
-
Re: Trivia game problem
Use
function of<windows.h>
10000 is in milliseconds