Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Assign colors to specific values in an array

–4 votes
asked Mar 22, 2019 by Jim Wilmes (160 points)
I am working on making a cribbage game, and I would like the hearts and diamonds to be printed red and the spades and clubs to be printed white. Is there an easy way to assign specific colors to each suit?

Below is the declaration of the suits, as well as the declaration for the deck:

wchar_t suits[4] = {0x2661, 0x2664, 0x2662, 0x2667};

for (i = 0; i < 13; i++) {
        for (j = 0; j < 4; j++) {
            deck[4 * i + j].rank = i + 1;
            deck[4 * i + j].value = i + 1;
            deck[4 * i + j].suit = suits[j];
            deck[4 * i + j].isUsed = false;
            deck[4 * i + j].isPlayed = false;
            if(i + 1 == 1){
                deck[4 * i + j].displayAs = 'A';
            }
            else if(i + 1 == 10){
                deck[4 * i + j].displayAs = 'T';
            }
            else if(i + 1 == 11){
                    deck[4 * i + j].displayAs = 'J';
                    deck[4 * i + j].value = 10;
            }
            else if(i + 1 == 12){
                    deck[4 * i + j].displayAs = 'Q';
                    deck[4 * i + j].value = 10;
            }
            else if(i + 1 == 13){
                    deck[4 * i + j].displayAs = 'K';
                    deck[4 * i + j].value = 10;
            }
            else{
                    deck[4 * i + j].displayAs = i + 0x31;
            }
        }
    }

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...