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

0 votes
asked Mar 22, 2019 by Jim Wilmes (200 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;
            }
        }
    }

1 Answer

0 votes
answered May 16 by Oliver 66 (290 points)
its as easy as copying and pasting: ❤️♦️♤♧, you can do ctrl+cmd+space on mac for more
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...