dimanche 13 novembre 2016

Multiple else if statements

i have this c code, regarding multiple if staments.. All statements are working nicely, except the final one.. It gets activated with other if statements and so ruins the result.. Any suggestions?

        for (i=0; i<(total); i++)
        {   for (n=0; n<((total)/4); n++)
            {   if (i==(0+(n*4)) && i<(total-5)&&(array[i]==0))
                {
                    array[i]=1;
                    i=n=500;                                     
                    break;
                    }


                else
                    if ((i==(3+(n*4)))&&i<(total-5)&&(array[i]==0))
                {
                    seatnr[i]=1;
                    i=n=500;
                    break;
                }
                else
                    if (i==(total)&&(array[i]==0))
                {
                    array[i]=1;
                    i=n=500;
                    break;
                    }
                else
                    if (i==(total-1)&&(array[i]==0))
                {
                    seatnr[i]=1;
                    i=n=500;
                    break;
                    }
                else printf("**Something**");
}}}

Aucun commentaire:

Enregistrer un commentaire