#1
  1. No Profile Picture
    dark angel
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2002
    Location
    in your mind....
    Posts
    2
    Rep Power
    0

    how come this generates blank??


    ive got a problem with this code,you see when i run it the questions dont seem to come out thoughit was initialized already,,am usin a linkedlist is there somethin wrong with my paramtr passin?
    Code:
    #include<stdio.h>
    #include<string.h>    
    #include<stdlib.h>
    
    #define MAX 48
    #define ERROR "Invalid Input!"
    #define NOT_FOUND -1
    /*variable declarations*/
    
    typedef char str20[21];
    typedef char str70[71];
    
    typedef struct
    {
    	str70 strQuestions;
    	str20 strChoices[4];
    	char  cAns;
    	int  nLevel;
    }struct_Game;
    struct structNode
    {
    	struct_Game sGame;
    	struct structNode *pGPrev,*pGNext;
    };
    typedef struct structNode structGNodeType;
    typedef structGNodeType *ptrGNode;
    
    /*Function: void initialize_question()					*
     * Purpose: This function initializes values for aGame			*
     * Returns: nothing							*/
    void initialize_question(ptrGNode *pGame,struct_Game sGame)
    { int i,j,k;
    	ptrGNode pRun,pNew;
    	i=0,j=0;
     /*copies value of string to array*/
    	
     	if(*pGame==NULL)
    	{
    	strcpy((*pGame)->sGame.strQuestions," Ano ang pambansang hayop ng Pilipinas?");
    	strcpy((*pGame)->sGame.strChoices[0],"aso");
    	strcpy((*pGame)->sGame.strChoices[1],"pusa");
    	strcpy((*pGame)->sGame.strChoices[2],"kalabaw");
    	strcpy((*pGame)->sGame.strChoices[3],"kabayo");
    	(*pGame)->sGame.cAns = 'c';(*pGame)->sGame.nLevel = 1;
    	(*pGame)->pGPrev=NULL;
    	(*pGame)->pGNext=NULL;
    	pRun=*pGame;
    	}
    	pNew =(ptrGNode)malloc(sizeof(structGNodeType));
    	
    	strcpy(pNew->sGame.strQuestions," Sino ang pumatay kay Magellan?");
    	strcpy(pNew->sGame.strChoices[0],"Raja Soliman");
    	strcpy(pNew->sGame.strChoices[1],"Si Malakas");
    	strcpy(pNew->sGame.strChoices[2],"Raja Ulayman");
    	strcpy(pNew->sGame.strChoices[3],"Lapu-Lapu");
    	pNew->sGame.cAns = 'd'; pNew->sGame.nLevel = 1;
    	pRun->pGNext=pNew;
    	pNew->pGPrev=pRun;
    	pNew->pGNext=NULL;
    	pRun=pRun->pGNext;
    
    	pNew = (ptrGNode)malloc(sizeof(structGNodeType));
    	strcpy(pNew->sGame.strQuestions," Ano ang pambansang awit ng Pilipinas?");
    	strcpy(pNew->sGame.strChoices[0],"Lupang Hinirang");
    	strcpy(pNew->sGame.strChoices[1]," Bayang Magiliw");
    	strcpy(pNew->sGame.strChoices[2]," Perlas ng Silanganan");
    	strcpy(pNew->sGame.strChoices[3]," Lupa ng Araw");
    	pNew->sGame.cAns = 'a'; pNew->sGame.nLevel = 1;
    	pRun->pGNext=pNew;
    	pNew->pGPrev=pRun;
    	pNew->pGNext=NULL;
    	pRun=pRun->pGNext;
    
    	pNew = (ptrGNode)malloc(sizeof(structGNodeType));
    	strcpy(pNew->sGame.strQuestions," Ano ang tagalog ng rectangle?");
    	strcpy(pNew->sGame.strChoices[0],"kwadrado");
    	strcpy(pNew->sGame.strChoices[1],"tatsulok");
    	strcpy(pNew->sGame.strChoices[2],"parihaba");
    	strcpy(pNew->sGame.strChoices[3],"parisukat");
    	pNew->sGame.cAns = 'c'; pNew->sGame.nLevel = 1;
    	pRun->pGNext=pNew;
    	pNew->pGPrev=pRun;
    	pNew->pGNext=NULL;
    	pRun=pRun->pGNext;
    
    	pNew =(ptrGNode)malloc(sizeof(structGNodeType));
    	strcpy(pNew->sGame.strQuestions," Ano ang pangalan ng seawitch sa Disney movie na LittleMermaid?");
    	strcpy(pNew->sGame.strChoices[0],"Ariel");
    	strcpy(pNew->sGame.strChoices[1],"Flounder");
    	strcpy(pNew->sGame.strChoices[2],"Cruella");
    	strcpy(pNew->sGame.strChoices[3],"Ursula");
    	pNew->sGame.cAns = 'd'; pNew->sGame.nLevel = 1;
    	pRun->pGNext=pNew;
    	pNew->pGPrev=pRun;
    	pNew->pGNext=NULL;
    	pRun=pRun->pGNext;
    
    	pNew =(ptrGNode)malloc(sizeof(structGNodeType));
    	strcpy(pNew->sGame.strQuestions,"Saan nobela ni Rizal makikita si SIMOUN?");
    	strcpy(pNew->sGame.strChoices[0],"Noli Me Tangere");
    	strcpy(pNew->sGame.strChoices[1],"El Filibusterismo");
    	strcpy(pNew->sGame.strChoices[2],"Florante at Laura");
    	strcpy(pNew->sGame.strChoices[3],"Mi Ultimo Adios");
    	pNew->sGame.cAns = 'b'; pNew->sGame.nLevel = 2;
    	pRun->pGNext=pNew;
    	pNew->pGPrev=pRun;
    	pNew->pGNext=NULL;
    	pRun=pRun->pGNext;
    
    	pNew =(ptrGNode)malloc(sizeof(structGNodeType));	
    	strcpy(pNew->sGame.strQuestions," Saan kilala si Gabriel Flash Elorde?");
    	strcpy(pNew->sGame.strChoices[0],"bowling");
    	strcpy(pNew->sGame.strChoices[1],"boxing");
    	strcpy(pNew->sGame.strChoices[2],"chess");
    	strcpy(pNew->sGame.strChoices[3],"karate");
    	pNew->sGame.cAns = 'b'; pNew->sGame.nLevel = 2;
    pRun->pGNext=pNew;
    	pNew->pGPrev=pRun;
    	pNew->pGNext=NULL;
    	pRun=pRun->pGNext;
    
    	
    	
    	
    }	
    
    
    /* Function: Game_mod(ptrGNode*pGame,struct_Game sGame)					*
     * Purpose: This function enters the user to the game proper		*/
    			
    void Game_mod(ptrGNode *pGame,struct_Game sGame)
    {	ptrGNode pTemp;
    	int nNum,nCtr=3,nTemp,nAmt_won;
    	char cCont,cChoice ,cEnter;
    	pTemp=*pGame;
    	int arrlifeline[3]={1,2,3}; 
    	int arrPeso_level[16] =
    	{0,1000,2000,3000,5000,10000,20000,30000,40000,50000,100000,200000,300000,500000,1000000,2000000};
    	initialize_question(&*pGame,sGame);
    	/*nTemp=rand()%15;*/
    	cCont = display_instructions(cCont);
    		if(cCont=='Y' || cCont=='y')
    		{	scanf("%c",&cEnter);
    		  do
    	 	  {
    printf("You are going to the %dlevel\n",arrPeso_level[nTemp+1]);
    
       		  printf("You have %d lifelines left\n",nCtr);
    
    		  printf("\nYour question is :\n");
    		  
    		/*Calls subfunction*/
    		  cChoice =  get_answer(pTemp,sGame);//this ones the problem
    			/*evaluates user's answer*/
    		do
    		{
    		if(cChoice!='a'&&cChoice!='b'&&cChoice!='c'&&cChoice!='d'&&
    		cChoice!='1'&&cChoice!='2'&&cChoice!='3'&&cChoice!='x')
    		{	  
    			  printf("Invalid answer!\n");
    			  printf("Enter your answer again");
    			  
    			  scanf("%c",&cChoice);
    		}
            	}while(cChoice!='a' && cChoice!='b' &&
    				cChoice!='c' && cChoice!='d'&&
    		cChoice!='1' && cChoice!='2' && cChoice!='3' &&
    		cChoice!='x');
    			scanf("%c",&cEnter);				
    			if(cChoice == pTemp->sGame.cAns)
    			{
    			  printf("That's correct!\n");
    			  nTemp++;
    			  pTemp=pTemp->pGNext;
    			}
    			else if(cChoice == 'x' || cChoice == 'X')
    			{
    			  printf("You chose to end this game\n");
    			  printf("You receive %d pesos\n",arrPeso_level[nTemp]);
    			  printf("Congratulations!");
    			}
    			else if(cChoice=='a'||cChoice=='b'||cChoice=='c'|| cChoice=='d')
    			{
                               printf("Sorry,Wrong answer!\n");
    			  printf("You receive %d pesos\n",arrPeso_level[nTemp]);
    				Menu(&*pGame,sGame);       
    			}	
                          else if(cChoice=='1' || cChoice=='2' ||
    				cChoice=='3')
    			 nCtr = display_lifeline(nCtr,arrlifeline,cChoice,sGame);
    		/* Condition for bringing incorrect answer to safelevel*/
    				if(arrPeso_level[nTemp]/5==0)
    				  nAmt_won=0;
    				else if(arrPeso_level[nTemp]/5==1)
    				  nAmt_won=10000;
    				else if(arrPeso_level[nTemp]/5==2)
    				  nAmt_won==100000;
    				else if(arrPeso_level[nTemp]/5==3)
    				 { nAmt_won==2000000;
    				  printf("You're our lucky Millionaire,Congratulations!!");		
    				}
    		  	 
    	}while(cChoice==pTemp->sGame.cAns||cChoice=='1'||cChoice=='2'||
    	 cChoice==3||cCont=='Y'||cCont=='y'&& nTemp <16);
    	}
    
    
    	/*else part to exit program*/
    	else
    		printf("Program aborted by user!\n\n");
    		
    	}	
    /*Function:display_instructions()				*
      *Purpose : Prints Welcome message and reads value for choice	*
      *Called by: game_mod()					*
      *Receives: cCont(character)					*
      *Returns: cCont(Character)					*/
     
    char display_instructions(char cCont)
    { 	clear_screen();
    	printf("\n");
    	printf("+-----------------------------------------------+\n");
    	printf("|		WELCOME TO		        |\n");
    	printf("|	WHO WANTS TO BE A MILLIONAIRE!!!	|\n");
    	printf("| To START------------------------------ TYPE Y	|\n");
    	printf("| To TERMINATE/END---------------------- TYPE N |\n");
    	printf("+-----------------------------------------------+\n");
    	do
    	{
    	  printf("Enter your choice:");
    	  scanf("%c",&cCont);
    	 
    		if(cCont!='Y'&& cCont!='y'&& cCont!='N'&& cCont!='n')
                    printf("Wrong choice!\n");
    	}while(cCont!='Y'&& cCont!='y'&& cCont!='N'&& cCont!='n');
    
    	return cCont;		
    }/*end of function*/
    
    /*Function: int display_lifeline()				*
     *Purpose : This function displays and updates lifeline		*
     *Returns: integer						*
     *Note:	 1- call-a-friend,2-50/50,3-ask-the-audience		*/
    int display_lifeline(int nCtr, int arrlifeline[],char cChoice,struct_Game sGame)
    {	
    	int  nCount;
    	if(cChoice =='1')
    		nCount = 1;
    	else if(cChoice =='2')
    		nCount = 2;
    	else if(cChoice=='3')
    		nCount = 3;
    		if(nCount<=3 && nCount>=1)
    		{
    		
    		if(nCount==arrlifeline[0])
    		{
    		  printf("You chose call-a-friend\n");
    		  printf("\nDialing...\n");
    		  delay();
    		  printf("Chris: I think the answer is %c
    			\n",&sGame.cAns);//this one also generated none
    		printf("I'm 100% sure!");
    		  arrlifeline[0]=5; /*assigns a different value to array*/
    		  nCtr--;
    		}
    		else if(nCount==arrlifeline[1])
    		{
    		  printf("You chose 50/50\n");
    			display_50(sGame);
    		  arrlifeline[1]=6;
    		  nCtr--;
    		}
    		else if(nCount==arrlifeline[2])
    		{
    		  printf("You chose ask-the-audience\n");
    		  puts("a.40%");
    		 puts("b.15%");
    		 puts("c. 20%");
    		  puts("d. 25%");
    		  arrlifeline[2]=7;
    		  nCtr--;
    		}	
    	}	
    	return nCtr;
            }	/*end of function*/
    
    /* Function: char get_answer()							*
     * Purpose: This Function displays the question and throws answer to main()	*
     * Returns: character								*/
    
    char get_answer(ptrGNode pGame,struct_Game sGame)
    {	
    	int j;
    	char cChoice;
    	
    	if(strcmp(pGame->sGame.strQuestions,""))
    	{	/* nTemp = rand()%15;*/
    		puts(pGame->sGame.strQuestions);
    		for(j=0;j<4;j++)
    		{
    			if(j==0)
    			{
    			printf("a.");
    			puts(pGame->sGame.strChoices[j]);
    			
    			}
    			else if(j==1)
    			{	
    			printf("b.");
    			puts(pGame->sGame.strChoices[j]);
    			
    			}
    			else if(j==2)
    			{	
    			printf("c.");
    			puts(pGame->sGame.strChoices[j]);
    			
    			}	
    			else if(j==3)
    			{	
    			printf("d.");
    			puts(pGame->sGame.strChoices[j]);
    			
    			}
    		
    		}
    		
    		
    	}
    	printf("What is your answer?");
    	scanf("%c", &cChoice);
    	return cChoice;		
    }	/*end of function*/
  2. #2
  3. *bounce*
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2002
    Location
    Delft, The Netherlands
    Posts
    514
    Rep Power
    42
    *sigh*

    Nobody's going to wade through that much code, you know. You'll have to be more specific.

    Try putting some diagnostic messages throughout your code (just some printf()'s will do), especially around code that you think -could- be part of the problem.

    Once you've isolated the problem and find yourself unable to solve it, you could try posting it here.

    Good luck :)
    "A poor programmer is he who blames his tools."
    http://analyser.oli.tudelft.nl/
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    190
    use your debugger! (nothing else to be added.....)

IMN logo majestic logo threadwatch logo seochat tools logo