Supermarket simulator C

-2

I have a problem with the following code. The exercise tries to simulate a row that has random number of people passing through three boxes, when a box is empty an element is removed from the original row and goes to box C1, C2 or C3 and once there after a delay the value of the number that is in any of those three boxes decreases; when that value is zero, it is removed from the box and remains empty so that another element of the original row enters the other. The problem is that when I run, the boxes show me garbage and according to me that should not happen.

void caja(FILA *F)
{
    FILA C1, C2, C3; crearFila(&C1); crearFila(&C2); crearFila(&C3);
    TipoDato a, b, c;
    do
    {
        x=dequeue(F);
        Sleep(2000);
        if (filaVacia(C1))
        {
            enqueue(&C1, x);

            if (a==0)
            {
                dequeue(&C1);
            }
        }
        else if (filaVacia(C2))
        {
            enqueue(&C2, x);
            if (b==0)
            {
                dequeue(&C2);
            }
        }
        else if (filaVacia(C3))
        {
            enqueue(&C3, x);
            if (c==0)
            {
                dequeue(&C3);
            }
        }
        system("cls");
        printf("\nFila: \n");
        imprime(*F);
        printf("\nCaja 1: \n");
        imprime(C1);
        printf("\nCaja 2: \n");
        imprime(C2);
        printf("\nCaja 3: \n");
        imprime(C3);
        if (!filaVacia(C1))
        {
            a=dequeue(&C1); a--; enqueue(&C1, a);
        }
        if (!filaVacia(C2))
        {
            b=dequeue(&C2); b--; enqueue(&C2, b);
        }
        if (!filaVacia(C3))
        {
            c=dequeue(&C3); c--; enqueue(&C3, c);
        }
    }while(!filaVacia(*F));
    printf("\n");
}
    
asked by Xpw _ 22.10.2017 в 20:07
source

1 answer

0
TipoDato a, b, c;
do
{
    x=dequeue(F);
    Sleep(2000);
    if (filaVacia(C1))
    {
        enqueue(&C1, x);

        if (a==0) // (1)
        {
            dequeue(&C1);
        }

In the first line you declare three variables: a , b , c . In (1) comparas a ... which is not initialized. And the same goes for the other two variables.

Without further information, everything points to the fact that your problem is that these three variables are not initialized.

    
answered by 23.10.2017 в 07:24