Join 4 Decks of cards

Viewed 37

I have this code and I intend to create a set of 4 decks, the problem is that in the suits, after the card 51 the result of the division gives 4 and the arrays of the suits do not return the initial position, how can I solve this situation?

Thank you

#include <stdio.h>
#define NCARTAS 52
int main()
{
    const char *numero[]= {"A","2","3","4","5","6","7","8","9","10","V","D","R"};
    const char *naipes[]= {"P","O","C","E"};
    char baralho[208];
    int posNumero,posNaipe;
    for(int i=0; i<208; i++)
    {
        baralho[i]=i;
        posNumero=i%13;
        posNaipe=i/13;

        printf("%s%s \n", numero[posNumero],naipes[posNaipe]);
    }  
}
1 Answers
posNaipe = i % NCARTAS / 13;

would do it. This is also a touchstone for your knowledge of operator precedence and associativity.

Related