#include <stdio.h>
#include<conio.h>
#include <string.h>
void main (void)
{
int cant,vpu[4],imp;
int vtp[4]={0};
int mxp[4][4]={0};
char vcm[4][4],vcp[4][4];
char cp[4],cm[4];
for(int i=0; i<4; i++)
{
fflush(stdin);
printf("cod. materia prima (4 caracteres mx) ");
gets(vcm[i]);
printf("precio x mg en $ (4mx)"); // cargo lote
scanf("%d",&vpu[i]);
}
int z=0;
printf("cant vend. ");
scanf("%d",&cant);
while(cant!=0)
{
fflush(stdin);
printf("cod. producto (4mx) (4 caracteres mx) ");
gets(cp);
printf("cod. materia prima (4 caracteres mx) ");
gets(cm);
int x=0; //
while(x<z && strcmp(vcp[x],cp)!=0)
x++;
if(x>=z)
{ //insercion cod. producto
strcpy(vcp[x],cp); // hice asi porque no se como usar la cadena como subindice
z++; // para acumular o contar etc..
} //
int k=0;
while(strcmp(vcm[k],cm)!=0 && k<4) //busca si exite la cod. materia y lo utiliza
k++;
imp=vpu[k]*cant;
vtp[x]+=imp;
mxp[x][k]+=cant;
printf("cant vend. ");
scanf("%d",&cant);
}
int aux;
char aux1[4];
for(int b=0; b<3; b++)
{
for(int c=b+1; c<4; c++)
if (vtp[b]<vtp[c])
{
aux=vtp[b];
vtp[b]=vtp[c];
vtp[c]=aux;
strcpy(aux1,vcp[b]);
strcpy(vcp[b],vcp[c]);
strcpy(vcp[c],aux1);
}
}
for(int h=0; h<4; h++)
{
printf( " cod. producto %s costo total %d \n",vcp[h],vtp[h]);
}
for(int l=0; l<4; l++)
{
int mx=0,pos;
for(int j=0; j<4; j++)
{
if(mxp[l][j]>mx)
{
mx=mxp[l][j]; // como no se repite cod producto cualquier cod. mat prima es el maximo
pos=j; // eso de la insercion se me hace q ta mal..
}
}
printf( " cod. producto %s la materia prima mx composicion es %s \n",vcp[l],vcm[pos]);
}
}