Problem with my code :( please help

This is a discussion on Problem with my code :( please help within the C Programming forums, part of the General Programming Boards category; So i'm trying to make a recursive program for a class im taking,but so far i can't seem to get ...

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    18

    Problem with my code :( please help

    So i'm trying to make a recursive program for a class im taking,but so far i can't seem to get it to run i've tried for 2 days now and just can't seem to get around the error's i'm getting. If you guy's and gal's could please take a look and see if you could help it would be greatly appreciated.Thank You

    Code:
    #define n 5
    enum Estados {Ninguno, Incluido, Excluido}
    struct elemento
    {
    	Estados estado;
    };
    typedef elemento TipoDato;
    int Pesos[n],OabjetivoAalcanzar;
    
    void Inicializa()
    {
    	Pesos[0]=7; Pesos=[1]=5; Pesos[2]=4; Pesos[3]=4; Pesos[4]=1;
    	OabjetivoAalcanzar=10;
    }
    Void MochilaExacta(int OabjetivoAalcanzar,int i,int *Solucion)
    {
    	int Encontrado,Posibilidad;
    	/*Finishes with success if siObjetivo=0 or if sio Objetivo<0 or i=n */
    	if((OabjetivoAalcanzar<=0)||(i==n))
    	   if(OabjetivoAalcanzar==0)
    	     *Solucion=1;
    	   else;/*dont do anything because Objetivo<0 or i=n */
    	else
    	{
    	   Posibilidad=0;
    	   Encontrado=0;
    	   do
    	   {
    	      Posibilidad++;
    	      switch(Posibilidad)
    	      {
    		 case 1:/*Inclusion*/
    		    MochilaExacta(OabjetivoAalcanzar-Pesos[i],i+1,&Encontrado);
    		    if(Encontrado)
    		       printf("%d",Pesos[i]); /*Its been included and has a solution*/
    		    break;
    		 case 2:/*Exclusion*/
    		    MochilaExacta(OabjetivoAalcanzar,i+1,&Encontrado);
    		    /*Even if Encontrado is true,there is nothing left to do*/
    	      }
    	   }
    	   while(!((Posibilidad==2)||Encontrado));
    	   *Solucion=Encontrado;
    	}
    }
    void MochilaExacta_N_R(int OabjetivoAalcanzar)
    {
    	int i,Solucion;
    	Pila *P;
    	lemento e,el;
    	i=0;
    	Solucion=0;
    	e.estado=Ninguno;
    	VaciaP(&P);
    	AnadeP(&P,e);/*Assigns the initial value to the pile P considering Pesos[0]*/
    	while(!EsVaciaP(P))
    	{
    	   e=PrimeroP(P);
    	   BorrarP(&P);
    	   if(Solucion)/*If you already have a solution then write it*/
    	   {
    	      if(e.estado==Incluido)
    		 printf("%d\n",Pesos[i]);/*Only written if something is included*/
    	      i--;
    	   }
    	   else
    	      if(((OabjetivoAalcanzar<=0)&&(e.estado==Ninguno))||(i==n))
    	      {
    		 if(OabjetivoAalcanzar==0)
    		    Solucion=1;/*A solution is always obtainable*/
    		 i--;/*the i hasnt been tested,You go back on the recursive*/
    	      }
    	   else/*There is no decision consider the state of the candidate*/
    	      switch(e.estado)
    	      {
    		 case Ninguno: /*1st it includes an advance in the recursive*/
    		    OabjetivoAalcanzar-=Pesos[i];
    		    i++;
    		    el.estado=Incluido;
    		    AnadeP(&P,el);
    		    el.estado=Ninguno;
    		    AnadeP(&P,el);
    		    break;
    		 case Incluido: /*Now the advance is excluded*/
    		    /*i-- is backed up;on option else of what*/
    		    OabjetivoAalcanzar+=Pesos[i];
    		    /*since it was removed it has to be added*/
    		    i++;
    		    el.estado=Excluido;
    		    AnadeP(&P,el);
    		    el.estado=Ninguno;AnadeP(&P,el);
    		    break;
    		 case Excluido:
    		    /*the current election didnt give any results ending recursivity*/
    		    i--;
    	 }
        }
    }
    void main (void)
    {
    	int Solucion;
    	Inicializa();
    	MochilaExacta(OabjetivoAalcanzar,0,&Solucion);
    	if(Solucion)
    	   printf("Solution given for Object=%d\n",OabjetivoAalcanzar);
    	Solucion=0;
    	OabjetivoAalcanzar=10;
    	MochilaExacta_N_R(OabjetivoAalcanzar);
    	if(Solucion)
    	   printf("A Solution was found");
    }

  2. #2
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    What exactly is the problem ? What is it you're trying to do ? You can't just post code and expect us to know what's supposed to be going on...
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    18
    Thats the thing i dont know what the problem is,i keep getting these 5 errors and i have no clue why,i mean i dont see the problem,It is a recursive program as i stated in the beginning.

    Errors im getting is:

    Code:
    enum Estados {Ninguno, Incluido, Excluido}
    struct elemento
    Too many types in declaration


    Code:
    struct elemento
    {
    	Estados estado;
    };
    Declaration missing ;


    Code:
    typedef elemento TipoDato;
    , expected

    Code:
    Pesos[0]=7; Pesos=[1]=5; Pesos[2]=4; Pesos[3]=4; Pesos[4]=1;
    Expression Syntax


    Code:
    Void MochilaExacta(int OabjetivoAalcanzar,int i,int *Solucion)
    Declaration Syntax Error

  4. #4
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,470
    missing ;
    Code:
    enum Estados {Ninguno, Incluido, Excluido};
    void is case sensetiv
    Pesos=[1] - remove =

    don't put too much on one line - it is hard for you to see typing erros in the long lines
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  5. #5
    Registered User
    Join Date
    May 2006
    Posts
    18
    Quote Originally Posted by vart
    missing ;
    Code:
    enum Estados {Ninguno, Incluido, Excluido};
    void is case sensetiv
    Pesos=[1] - remove =

    don't put too much on one line - it is hard for you to see typing erros in the long lines
    Thank you lol fixing those 2 errors gave me a whopping 9 now lol i suck

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code problem
    By sybariticak47 in forum C++ Programming
    Replies: 9
    Last Post: 02-28-2006, 10:50 AM
  2. Problem with game code.
    By ajdspud in forum C++ Programming
    Replies: 5
    Last Post: 02-14-2006, 05:39 PM
  3. problem with selection code
    By DavidP in forum Game Programming
    Replies: 1
    Last Post: 06-14-2004, 01:05 PM
  4. Replies: 5
    Last Post: 12-03-2003, 04:47 PM
  5. Help with code for simple Y2K problem
    By Mule in forum C++ Programming
    Replies: 3
    Last Post: 03-05-2003, 11:53 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21