I have a program due that is to take 5 random cards from a deck, declare what suit they are and give the number of the card. Ul;timately what i need to do after this is to have them filter the cards into like numerical order.... basically put them lowest to highest ( from top to bottom) I got the code for this worked out but I am unsure how to get it to display H,C,S, or D for the suits. I got it to do a random number 0-4 for that display but I cant get it to display H C S or D. Also I am unable to get it to sort the array. I am unsure of the code and I know its really simple for all you people who do it all the time but its a basic beginner course and im having a bit of a hard time. Ill paste the code below. Any help is greatly appreciated
Code:#include <stdio.h> #include <stdlib.h> #include <time.h> int main() { int iValue, iSuit; int iLoop, iLoop2; float position[3]; bool bCards[4][13]; // Initializing the array // aka, putting all of the cards in the deck for(iLoop = 0; iLoop < 4; iLoop++) for(iLoop2 = 0; iLoop2 < 13; iLoop2++) bCards[iLoop][iLoop2] = 1; // Seeding the random number generator srand(time(NULL)); printf("\n\n"); printf("Suit Value"); printf("\n"); printf("---- -----"); printf("\n"); for(iLoop = 0; iLoop < 5; iLoop++) { iSuit = rand()%4; iValue = rand()%13; while(bCards[iSuit][iValue] == 0) { iSuit = rand()%4; iValue = rand()%13; } printf(" %2d %2d", iSuit, iValue); printf("\n"); // Removing the card from the deck bCards[iSuit][iValue] = 0; } system("PAUSE"); return 0; }



LinkBack URL
About LinkBacks


