Hello All!
I was trying to create a random card, like from a deck of cards, and I've been having some trouble. If there was a way to return a char, I feel the problem would be much easier. (I realize I could do the same thing assigning a global variable)
I'm VERY new to coding, so take it easy on me!
I want to return the rank variable, which is either an int or a char, depending on it's original value.Code:int card (void) {
//Draws a random card
srand(time(NULL));
int cardNum = rand()%13;
int tag = rand()%4;
//Assigns rank of card, and returns it
if (cardNum >= 10) {
if (cardNum == 10)
char rank = 'J';
else if (cardNum == 11)
char rank = 'Q';
else if (cardNum == 12)
char rank = 'K';
else if (cardNum == 13)
char rank = 'A';
}
else int rank = cardNum +2;
//Assigns suit of card, and modifies a global character
if (tag == 0)
suit = 'D';
else if (tag == 1)
suit = 'C';
else if (tag == 2)
suit = 'H';
else suit = 'C';
return rank;
}