Help

This is a discussion on Help within the C Programming forums, part of the General Programming Boards category; Hello, sorry for my bad English. I am from Argentina. I have a problem with this ejercice with functions. Error ...

  1. #1
    Registered User
    Join Date
    Jun 2012
    Posts
    1

    Help

    Hello, sorry for my bad English. I am from Argentina. I have a problem with this ejercice with functions.
    Error in functions void "maximo".
    Help me please. I am Noob with C.

    The text are Spanish in Code.

    Code:

    Code:
    #include <stdio.h>#include <conio.h>
    
    
    
    
    //Void
    void Cantavend (int, int, int);
    void sucmax (int, float);
    void sucrecmenos (int, float);
    void gansuc(float, float, float, float, float);
    void porrec(float, float, float, float);
    void tickme(int, float);
    void Imprimir (int);
    void procav (float, float, float, float, float);
    void Suma (int*, int);
    void Suma2(float*, float);
    void maximo(int, float*, float, int*, float, float*, float, int*, int, int*, int, float*);
    
    
    //Float
    float descuento (float a);
    float gsuca (float);
    float promedio (float, float);
    float promediotot (float, float);
    
    
    int main ()
    {
        int tick,ca,npel,nsuc,turno,catm,catn,catt,cont,tots1,tots2,tots3,tots4,tots5,pg,aux,aux2,aux3; //Variables Enteras
        float pr,recp1,recp2,recp3,recp4,recs1,recs2,recs3,recs4,recs5,tickmin,gsuc1,gsuc2,gsuc3,gsuc4,gsuc5,totrecp,totfinal,prom1,prom2,prom3,prom4,proms1,proms2,proms3,proms4,proms5,pmaxr,sucminr; //Variables Flotantes
        tick=ca=npel=nsuc=turno=catm=catn=catt=cont=tots1=tots2=tots3=tots4=tots5=pg=aux=aux2=aux3=0;
        pr=recp1=recp2=recp3=recp4=recs1=recs2=recs3=recs4=recs5=tickmin=gsuc1=gsuc2=gsuc3=gsuc4=gsuc5=totrecp=totfinal=prom1=prom2=prom3=prom4=proms1=proms2=proms3=proms4=proms5=pmaxr=sucminr=0;
        printf("Ingrese numero de ticket ");
        scanf("%d",&tick);
        while (tick!=0) //Comienzo del ciclo
        {
              printf("\nIngrese numero de sucursal ");
              scanf("%d",&nsuc);
              printf("\nIngrese cantidad de asientos ");
              scanf("%d",&ca);
              printf("\n1=Belleza americana \n2=El informante \n3=La hija del general \n4=Al filo de la muerte \n\nIngrese numero de pelicula ");
              scanf("%d",&npel);
              printf("\n1=Turno Mañana \n2=Turno Tarde \n3=Turno Noche \n\nIngrese numero de turno  ");
              scanf("%d",&turno);
              
              if (ca > 8) //Verificar descuento
              {
                       pr=descuento(ca);
              }
              if (ca<=8)
              {
                  pr=ca*7;
              }
              
              switch (turno) //Categoría Turno
              {
                     case 1:Suma(&catm,ca);
                     break;
                     case 2:Suma(&catt, ca);
                     break;
                     case 3:Suma(&catn,ca);
                     break;  
              }
              
              switch (npel) //Categoría pelicula
              {
                     case 1:Suma2(&recp1,pr);
                     break;
                     case 2:Suma2(&recp2,pr);
                     break;
                     case 3:Suma2(&recp3,pr);
                     break;
                     case 4:Suma2(&recp4,pr);
                     break;
              }
              
              switch (nsuc) //Categoría numero de sucursal
              {
                     case 1:Suma2(&recs1,pr);
                     Suma(&tots1,ca);
                     break;   
                     case 2:Suma2(&recs2,pr);
                     Suma(&tots2,ca);
                     break;
                     case 3:Suma2(&recs3,pr);
                     Suma(&tots3,ca);
                     break;
                     case 4:Suma2(&recs4,pr);
                     Suma(&tots4,ca);
                     break;
                     case 5:Suma2(&recs5,pr);
                     Suma(&tots5,ca);
                     break;
              }
              
              cont=cont+1;
              maximo(cont, &pmaxr, recp1, &aux, npel, &tickmin, pr, &aux2, tick, &aux3, nsuc, &sucminr);
              
              if (turno == 2 && nsuc == 3 && npel == 2) //Pelicula 2, Sucursal 3, Turno Tarde
              {
                        Suma(&pg,ca);
              }
    
    
              printf("\nIngrese numero de ticket ");
              scanf("%d",&tick);
        }
        
        // Fin del ciclo
        
        //Operaciones
        gsuc1=gsuca(recs1);
        gsuc2=gsuca(recs2);
        gsuc3=gsuca(recs3);
        gsuc4=gsuca(recs4);
        gsuc5=gsuca(recs5);
        totrecp=recp1+recp2+recp3+recp4;
        prom1=promedio(recp1,totrecp);
        prom2=promedio(recp2,totrecp);
        prom3=promedio(recp3,totrecp);
        prom4=promedio(recp4,totrecp);
        totfinal=tots1+tots2+tots3+tots4+tots5;
        proms1=promediotot(tots1,totfinal);
        proms2=promediotot(tots2,totfinal);
        proms3=promediotot(tots3,totfinal);
        proms4=promediotot(tots4,totfinal);
        proms5=promediotot(tots5,totfinal);
        
        //Resultados
        Cantavend(catm,catt,catn);
        sucmax(aux,pmaxr);
        sucrecmenos(aux3,sucminr);
        gansuc(gsuc1,gsuc2,gsuc3,gsuc4,gsuc5);
        porrec(prom1,prom2,prom3,prom4);
        tickme(aux2,tickmin);
        Imprimir(pg);
        procav(proms1,proms2,proms3,proms4,proms5);
        
        
        getch();
        return 0;
        
    }
    
    
    float descuento(float a)
    {
          float b;
          b=(a*7)*0.9;
          return b;
    }
    float gsuca(float a)
    {
          float b;
          b=a*0.2;
          return b;
    }
    float promedio(float a, float b)
    {
          float c;
          c=(a*100)/b;
          return c;
    }
          
    float promediotot (float a, float b)
    {
          float c;
          c=(a*100)/b;
          return c;
    }
          
    
    
    void Cantavend (int a, int b, int c)
    {
         printf("La cantidad de asientos vendidos en el turno mañana es %d,en el turno tarde %d, y en el noche %d \n\n",a,b,c);
    }
    
    
    void sucmax (int a, float b)
    {
         printf("La pelicula de mayor recaudacion es la nro %d, que recaudo %5.2f \n\n",a,b);
    }
    
    
    void sucrecmenos (int a, float b)
    {
         printf("La sucursal que recaudo menos fue la numero %d, con un total de %5.2f \n\n",a,b);
    }
    
    
    void gansuc (float a, float b, float c, float d, float e)
    {
         printf("Lo que gano cada sucursal es: \n1.%5.2f  \n2. %5.2f \n3.%5.2f \n4.%5.2f \n5.%5.2f \n\n",a,b,c,d,e);
    }
    
    
    void porrec(float a, float b, float c, float d)
    {
         printf("El porcentaje recaudado de cada pelicula sobre el total es: \n1. %5.2f \n2. %5.2f \n3. %5.2f \n4. %5.2f \n\n",a,b,c,d);
    }
    
    
    void tickme (int a, float b)
    {
         printf("El ticket de menor valor es el nro %d, con un valor de %5.2f \n\n",a,b);
    }
    
    
    void Imprimir (int a)
    {
         printf("La cantidad de asientos vendidos para la pelicula 2, la sucursal 3 y turno tarde es %d \n\n",a);
    
    
    } 
    
    
    void procav (float a, float b, float c, float d, float e)
    {
         printf("El promedio de asiento vendidos para cada sucursal es: \n1. %5.2f \n2. %5.2f \n3. %5.2f \n4. %5.2f \n5. %5.2f \n\n",a,b,c,d,e);
    }
    
    
    void Suma (int*a, int b)
    {
         *a=*a+b;
    }
          
    void Suma2 (float*a, float b)
    {
         *a=*a+b;
    }
    
    
    void maximo(int cont, float *pmaxr, float recp1, int *aux, float npel, float *tickmin, float pr, int *aux2, int tick, int *aux3, int nsuc, float *sucminr)
    {
             if (cont==1)
              {
                          *tickmin=pr;
                          *aux2=tick;
                          *aux3=nsuc;
                          *pmaxr=0;
                          *sucminr=pr;
              }
              if (recp1>pmaxr)
              {
                               *pmaxr=recp1;
                               *aux=npel;
              }
              if (recp2>pmaxr)
              {
                               *pmaxr=recp2;
                               *aux=npel;
              }
              if (recp3>pmaxr)
              {
                               *pmaxr=recp3;
                               *aux=npel;
              }
              if (recp4>pmaxr)
              {
                               *pmaxr=recp4;
                               *aux=npel;
              }
                               
              if (pr < tickmin)
              {
                     *tickmin=pr;
                     *aux2=tick;
              }
              if(recs1<sucminr&&recs1>0||recs1==sucminr+pr) 
              {
                               *sucminr=recs1;
                               *aux3=nsuc;
              }
              if(recs2<sucminr&&recs2>0||recs2==sucminr+pr)
              {
                               *sucminr=recs2;
                               *aux3=nsuc;
              }
              if(recs3<sucminr&&recs3>0||recs3==sucminr+pr)
              {
                               *sucminr=recs3;
                               *aux3=nsuc;
              }
              if(recs4<sucminr&&recs4>0||recs4==sucminr+pr)
              {
                               *sucminr=recs4;
                               *aux3=nsuc;
              }
              if(recs5<sucminr&&recs5>0||recs5==sucminr+pr)
              {
                               *sucminr=recs5;
                               *aux3=nsuc;
              }
    }

    Goodbye.

  2. #2
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,181
    Code:
        int tick,ca,npel,nsuc,turno,catm,catn,catt,cont,tots1,tots2,tots3,tots4,tots5,pg,aux,aux2,aux3; //Variables Enteras
        float pr,recp1,recp2,recp3,recp4,recs1,recs2,recs3,recs4,recs5,tickmin,gsuc1,gsuc2,gsuc3,gsuc4,gsuc5,totrecp,totfinal,prom1,prom2,prom3,prom4,proms1,proms2,proms3,proms4,proms5,pmaxr,sucminr; //Variables Flotantes
        tick=ca=npel=nsuc=turno=catm=catn=catt=cont=tots1=tots2=tots3=tots4=tots5=pg=aux=aux2=aux3=0;
        pr=recp1=recp2=recp3=recp4=recs1=recs2=recs3=recs4=recs5=tickmin=gsuc1=gsuc2=gsuc3=gsuc4=gsuc5=totrecp=totfinal=prom1=prom2=prom3=prom4=proms1=proms2=proms3=proms4=proms5=pmaxr=sucminr=0;

    MY BRAIN IS TRYING TO ESCAPE!

    You... you really need to invest some time into learning arrays.

    That should be a priority in your programming time.

    [Edit]
    You didn't ask any questions or explain what errors you get so I didn't offer any answers or suggest and bug fixes.
    [/Edit]

    Soma

  3. #3
    Registered User
    Join Date
    Dec 2005
    Posts
    134
    I hope you are facing problem in compiling itself...
    Code:
    float *pmaxr, float recp1
    
              if (recp1>pmaxr)
              {
                               *pmaxr=recp1;
                               *aux=npel;
              }
              if(recs1<sucminr&&recs1>0||recs1==sucminr+pr)
              {
                               *sucminr=recs1;
                               *aux3=nsuc;
              }
    You are comparing a variable value and an address!! Adding a variable value and an address!! Pointers are not meant to work this way.
    You must first read some C programming book to understand pointers.
    S_ccess is waiting for u. Go Ahead, put u there.

Popular pages Recent additions subscribe to a feed

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