1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Help with Mastermind in C!

Discussion in 'C' started by dagar5, Mar 21, 2009.

  1. dagar5

    dagar5 New Member

    Joined:
    Mar 21, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hey guys, im developing for my class a simple masterming game, i have accomplished allot and im feeling very good, but im having troubles going forward. After i declare some rules and some integers and stuff, my program doesn't recognize any new functions.. can someone check out my code and see what am i doing wrong??

    Thanks!!

    HTML:
    <code>
    #include <stdio.h>
    #include <stdlib.h>
    #include <curses.h>
    #include <iostream>
    
    int n1,n2,n3,n4,n5,n6,n7,n8;
    int cont=0,respuestasAcertadas=0,numeroIntentos=0,volver=100;
    char x,y;
    
    void introduccionPrograma()
    {
    	printf("Bienvenidos a Master Mind, presione enter para continuar!");
    	scanf("%c",&x);
    }
    
    void instruccionPrograma()
    {
    	printf("A continuacion, usted jugara a Master Mind. Este juego consta de \ndos partes:\nUna en la cual el Jugador #1 introduce 4 numeros del 1 al 4 al azar \nY otra parte en la cual el Jugador #2 trata de adivinar la secuencia\nintroducida por el Jugador #1.");
    	scanf("%c",&x);
    }
    
    void reglasPrograma()
    {
    	printf("Las reglas son: ");
    	printf("\n");
    	printf("1) Introducir unicamente numeros enteros del 1 al 4");
    	printf("\n");
    	printf("2) No repetir numeros al momento de intruducir las combinaciones");
    	printf("\n");
    	printf("3) No ver la pantalla de su companero al momento que el mismo introduzca \nlas combinaciones");
    	printf("\n");
    	printf("4) Disfrutar del juego!!");
    }
    
    void comenzarPrograma()
    {
    	printf("Presiona enter cuanto esten listos para comenzar...");
    	scanf("%c",&x);
    }
    
    void leerVariables1()
    {
    	printf("Introduzca el primer valor: ");
    	scanf("%d",&n1);
    	
    	while(cont<volver)
    	{
    		if(n1>=1 and n1<=4)
    		{
    			printf("Introduzca el segundo valor: ");
    			scanf("%d",&n2);
    			
    			while(cont<volver)
    			{
    				if(n2 != n1 and n2>=1 and n2<=4)
    				{
    					printf("Introduzca el tercer valor: ");
    					scanf("%d",&n3);
    					
    					while(cont<volver)
    					{
    						if(n3 != n1 and n3 != n2 and n3>=1 and n3<=4)
    						{
    							printf("Introduzca el cuarto valor: ");
    							scanf("%d",&n4);
    							while(cont<volver)
    							{
    								if(n4 != n1 and n4 != n2 and n4 != n3 and n4>=1 and n4<=4)
    								{
    									system("CLEAR");
    									printf("Excelente, ahora puedes darle el computador al Jugador #2");
    									scanf("%c",&x);
    								}
    								else
    									printf("Error!, Vuelva a introdrucir el valor: ");
    									scanf("%d",&n4);
    									cont=cont+1;
    							}	
    						}
    						else
    							printf("Error!, Vuelva a introdrucir el valor: ");
    							scanf("%d",&n3);
    							cont=cont+1;
    					}	
    				}
    				else
    					printf("Error!, Vuelva a introdrucir el valor: ");
    					scanf("%d",&n2);
    					cont=cont+1;
    			}	
    		}
    		else
    			printf("Error!, Vuelva a introdrucir el valor: ");
    			scanf("%d",&n1);
    			cont=cont+1;
    	}	
    }
    
    
    
    
    int main (int argc, char * const argv[]) 
    {
    	introduccionPrograma();
    	printf("\n");
    	printf("\n");
    	instruccionPrograma();
    	printf("\n");
    	printf("\n");
    	reglasPrograma();
    	printf("\n");
    	printf("\n");
    	comenzarPrograma();
    	printf("\n");
    	printf("\n");
    	leerVariables1();
    	system("PAUSE");
    	leerVariables2();
    }
    </code>
    
     
  2. dagar5

    dagar5 New Member

    Joined:
    Mar 21, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Also I want to know if there is a way to force the program to go from leerVariables1() to leerVariables2(), because thats where the problem is.. everytime I set some rules for leerVariables2() when executing i dont get anything on screen!

    Thanks
     
  3. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    What errors do you get when you try to compile the code? It's not clear what you mean by "my program doesn't recognize any new functions".

    "and" is not a C keyword. Use && for logical and, or & for bitwise and.

    To go from leerVariables1() to leerVariables2() you can just call them one after the other, for example:
    Code:
    void func()
    {
      leerVariables1();
      leerVariables2();
    }
    
    However, leerVariables2() doesn't appear to be defined anywhere.
     

Share This Page