This section of code was taken out of a program that assigns an array of 52 card objects a number and a suit (a deck of cards). Then it displays the ordered deck, shuffles it and then displays the shuffled deck.
Heres the enum:
Code:
enum Suit { clubs, diamonds, hearts, spades };
Here's the excerpt of code that my question lies. My problem is highlighted in red:
Code:
...
void main()
{
card deck[52];
cout << endl;
for(int j=0; j<52; j++)
{
int num = (j % 13) + 2; // cycles through 2 to 14, 4 times
Suit su = Suit(j / 13); // cycles through 0 to 3, 13 times
deck[j].init(num, su); // sets card member data
}
}...
I don't understand why (j / 13) is casted. Wouldn't
j / 13 be the same without the Suit cast?