Advice for my Perfect Card Shuffle Program

Hey guys,
I have the "Create a deck of Cards, perform perfect shuffle, and return to original order" - hw assignment, and it all works great!

The only thing I'm looking for advice on is how to make my card 'number' assignments a little more automated. Right now the program is pretty dynamic based upon how large of a Decksize you use, except when it comes to assigning numbers. Posted working code is below, any insight on how to make it a little cleaner would be much appreciated!

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
 void cardType::setCardType(const int& c){

      //COUNT (C) IS STARTING AT 1
      cardCount = c;                            //keeps track of # of cards made, and assigns new card based on value(suit, num)

      if (cardCount <= (DECKSIZE * 1/4)){
            suit = " Hearts";
      }
      else if (cardCount > (DECKSIZE * 1/4) && cardCount <= (DECKSIZE * 1/2)){
            suit = " Spades";
      }
      else if (cardCount > (DECKSIZE * 1/2) && cardCount <= (DECKSIZE * 3/4)){
            suit = " Diamonds";
      }
      else if (cardCount > (DECKSIZE * 3/4)  && cardCount <= DECKSIZE){
            suit = " Clubs";
      }

      switch(cardCount)
      {
            case 1:case 14:case 27:case 40: number  = "2 "; break;
            case 2:case 15:case 28:case 41: number  = "3 "; break;
            case 3:case 16:case 29:case 42: number  = "4 "; break;
            case 4:case 17:case 30:case 43: number  = "5 "; break;
            case 5:case 18:case 31:case 44: number  = "6 "; break;
            case 6:case 19:case 32:case 45: number  = "7 "; break;
            case 7:case 20:case 33:case 46: number  = "8 "; break;
            case 8:case 21:case 34:case 47: number  = "9 "; break;
            case 9:case 22:case 35:case 48: number  = "10"; break;
            case 10:case 23:case 36:case 49: number = "J "; break;
            case 11:case 24:case 37:case 50: number = "Q "; break;
            case 12:case 25:case 38:case 51: number = "K "; break;
            case 13:case 26:case 39:case 52: number = "A "; break;
      }
}
The usual way is to start counting at 0, and then do this.
1
2
suit = cardCount / 13;
rank = cardCount % 13;


If you also want a number string, then use rank to index into an array.
rank may be not ideal as designation for a variable. See
http://www.cplusplus.com/forum/general/252307/#msg1111303

BTW, you may find there an other kind to shuffle and dial a card deck that was perfect for me.
ahhh, I'm going to try and set up an enum for the number assignment, and try and run a modulo loop for assigning them, thank you!
I would regard value for counting and sequence of significance during play separately. I know card games where numbers below 10 do not count at all, I know games where numbers below 9 are not part of the deck, I heard of card games where the 9 of trump suit is "high" (changed sequence of significance). So it depends on the kind of card game how you may "picture" it in C++.
Just for fun here a clip from Swiss Television of 1967 explaining "Jass" I grasp almost nothing (just that only three ways to shuffle are allowed), unknown wording, no ordinary playing cards (frensch face) -- https://www.youtube.com/watch?v=PryRCcilAP8
Topic archived. No new replies allowed.