# Thread: Deck of cards - Easy to understand program

1. ## Deck of cards - Easy to understand program

I'm trying to make a deck of cards using c programming. I want it so the computer will ask me for a number from 1-52 and each of the numbers will correspond to a card. I've got as far as the program printing every card but I have no idea how to make a card "whole". I have all the numbers and all the suits but they are in no way attached, they just print up at together. Can anyone help please.

Code:
```#include <stdio.h>

int main(void) {

char value[14][6]={"Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Jack","Queen","King","Ace"};
char suit[4][9]= {"Hearts", "Diamonds", "Clubs", "Spades"};

int i=0;
int j=0;

for (i=0; i<13; i++){
for (j=0; j<4; j++){
printf("The %s of %s\n\n", value[i], suit[j]);
}
}
system("pause");
}```
All this does is print each number 4 times and cycles through the suits.

Also I'm relatively new to c programming so if possible could the programming be kept at a level easy to understand.
Thanks!

2. A simple solution is to calculate the indices for your "value" and "suit" arrays for any number between 1 and 52.
Hint: imagine your cards are ordered by suits (first 13 cards are hearts, next 13 cards are diamonds, ...) and then use division and modulo/remainder.

Code:
`char value[14][6]={"Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Jack","Queen","King","Ace"};`
There are only 13 cards for each suit.

Bye, Andreas

3. Shouldn't it be 1-56?
Use scnaf in order to make the computer get a number from the keyboard.
Then you could use Andreas idea

4. Originally Posted by std10093
Shouldn't it be 1-56?
Use scnaf in order to make the computer get a number from the keyboard.
Then you could use Andreas idea
No, the 14 was a mistake, there are 13 cards per suit, 13x4 = 52

Unless you have a 500 pack (having 11's, 12's, 13's) in which case there are 16 cards per suit for a total of 64 cards.

5. Oh ok iMalc.I do not know about card and decks,i just read the code