How to initialize an array of records for 52 playing cards?

closed account (oN3h0pDG)
Hello, I'm trying to initialize a array of 52 playing cards and I'm not really sure how to do it and what the right syntax is. I was going to use a for loop and initialize every 13 cards to one of the four suits (Hearts, Diamonds, Clubs, Spades) but I'm unsure on how to write it. I have a struct with a char value for the suit and a int for the number value. If you could please help me figure out how to initialize a array of playing card records that would be greatly appreciated, thank you! :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

#include <iostream>
using namespace std;

// record containing a playing card
struct card {

	char cardSuit; // Hearts, Diamonds, Clubs, or Spades
	int cardValue; // Card value from 1 to 13

};

// Procedure that initilizes
void initilize() {

	card deck[52]; //  An array of cards named deck of size 52
	
	for (int i = 0; i < 52; i++) {
		
		// ????????????????????????
		
	}

}

int main() {

	

	initilize(); // Initilize deck

	return 0;
}

Last edited on
closed account (48T7M4Gy)
http://www.cplusplus.com/forum/beginner/62103/
Topic archived. No new replies allowed.