help with card shuffling please!!

hi, im trying to shuffle a deck of cards, and it keeps coming out in order. I have no idea what i'm doing wrong, please help!
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>



 using namespace std;

 class Card
{
    private: string suit; int value;

    public:
            Card()//default constructor (no arguments) allows you to make an
            {     //array
                value = 0;
            }

            Card(int v, string s)// allows the private attributes to be set
            {
                value = v;
                suit = s;
            }

            int getvalue()// returns the cards value
            {
                return value;
            }

            string getsuit()// returns the cards suit
            {
                return suit;
            }
};

class Deck
{
        /** these private vectors are the deck, and the pointers to the deck */
    private: vector<Card> cardvector; vector<Card *> pcardvector;

    public:
    /** this constructor also uses a for loop to create a pointer for each card */
            Deck (vector<Card> cardvector2)
            {
                cardvector = cardvector2;

                for (size_t x = 0; x < cardvector.size(); ++x)
                {
                    pcardvector.push_back(&cardvector[x]);
                }
            }
/** by printing with the pointers, it allows me to shuffle the pointers later on
rather than the actual deck, this is good because i still have my original deck.
 */
            void printdeck ()
            {
                for (size_t x = 0; x < pcardvector.size(); ++x)
                {
                    switch(pcardvector[x]->getvalue())
                    {
                        case 1: cout << "Ace"; break;

                        case 11: cout << "Jack"; break;

                        case 12: cout << "Queen"; break;

                        case 13: cout << "King"; break;

                        default: cout << pcardvector[x]->getvalue(); break;
                    }
                    cout << " of ";
                    cout << pcardvector[x]->getsuit() << endl;

                }cout << endl;
            }

            void nextcard ()
            {

            }

            void shufflecards ()
            {
                random_shuffle(pcardvector.begin(),pcardvector.end());
            }
};
vector<Card> deck1;
/** this void function creates a vector of 'card' objects using the push_back
     function*/
void createDeck()
{
    int n,i,j;
    string b;
    j = 0;

    for(n = 0; n < 4; n++)
    {
        for(i = 1; i < 14; ++i)
        {
            switch (n)
            {
                case 0: b = "Hearts";
                break;

                case 1: b = "Spades";
                break;

                case 2: b = "Diamonds";
                break;

                case 3: b = "Clubs";
                break;
            };

            deck1.push_back(Card(i, b));

        }
    }

}

/** i have placed the above created deck as the argument for the deck class
    constructor, and called for the printdeck function to be used.*/
int main(array<System::String ^> ^args)
{
    srand ( time(NULL) );
    
	createDeck();
	Deck(deck1).shufflecards();
    Deck(deck1).printdeck();
    
    
    system("pause");
}
Last edited on
You are throwing away the results because lines 134 and 135 are working with temporaries.

133
134
135
136
	createDeck();
	Deck deck(deck1);
	deck.shufflecards();
	deck.printdeck();

Hope this helps.
also int j was not being used
Topic archived. No new replies allowed.