not sure what could be wrong

ok, so i am making a cribbage game, i had it so it printed the first hand, allowed you to discard 1, and again for a second card, then the same for the second hand, followed by then adding the starter card to the vectors, then adding up the score(the scoring isnt complete yet but i cant work on it untill it works), but i had a separate function to print each vector(hands and deck), sort each hand and to discard from each hand, so i altered the functions so you just pass an arguement through, making my code shorter, however the program now just prints the first hand and asks for which one to dicard, but on the print, the sort hasnt worked, and upon discarding, that appears to not work, however when i tested a print of the discarded cards, the ones i discarded appeared, however they were not removed from the hand, so it moves correctly, so either the sort and discard functions do not work, or there is something wrong with printing function, all these functions are in a class, here is my int main:

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
#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include "class.cpp"
#include "deck class.cpp"

using namespace std;

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));

        }
    }
}

int main()
{
   cout << "welcome to Andrew's crib game" << endl;
    cout << endl;
    srand ( time(NULL) );
    createDeck();
    Deck deckofcards(deck1);
    deckofcards.game();
    return 0;
}


and here is my class:

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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

class Deck
{
        /** these private vectors are the deck, and the pointers to the deck */
    private: vector<Card> cardvector; vector<Card *> pcardvector;
             vector<Card *> hand1; vector<Card *> hand2; Card * ncard;
             vector<Card *> crib; Card * startercard; int tscore1;
             int tscore2; int tscorec;

    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]);
                }
                tscore1 = 0;
                tscore2 = 0;
                tscorec = 0;
            }

            ~Deck ()
            {
                for (int x = 0; x < 52; ++x)
                {
                    pcardvector.pop_back();
                }

                for (int x = 0; x > 4; ++x)
                {
                    hand1.pop_back();
                    hand2.pop_back();
                }
            }

            int getscore1 ()
            {
                return tscore1;
            }

            int getscore2 ()
            {
                return tscore2;
            }

            int getscorec ()
            {
                return tscorec;
            }
/** by printing with the pointers, it allows me to shuffle the pointers later on
rather than the actual deck */
            void printing (vector<Card *> print)
            {
                for (size_t x = 0; x < print.size(); ++x)
                {
                    cout << x + 1 << "-    ";
                    switch(print[x]->getvalue())
                    {
                        case 1: cout << "Ace"; break;

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

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

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

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

                }cout << endl;
            }
/** this function creates assigns the 'ncard; pointer to the next in line
    depending on the hand sizes*/
            void nextcard ()
            {
                ncard = pcardvector.back();
            }

            void shufflecards ()
            {
                random_shuffle(pcardvector.begin(),pcardvector.end());
            }

            void dealcards ()
            {
                for (int x = 0; x < 6; ++x)
                {
                    hand1.push_back(pcardvector.back());
                    pcardvector.pop_back();
                };

                for (int x = 0; x < 6; ++x)
                {
                    hand2.push_back(pcardvector.back());
                    pcardvector.pop_back();
                };
            }

            void discarding (vector<Card *> discard)
            {
                unsigned j;
                cin >> j;

                if (j != discard.size())
                {
                    swap(discard[j - 1],discard.back());
                }

                crib.push_back(discard.back());
                discard.pop_back();
            }

            void sorthand (vector<Card *> sorting)
            {
                for (unsigned n = 0; n < sorting.size(); ++n)
                {
                    for (unsigned j = 0; j < sorting.size() - 1; ++j)
                    {
                        if (sorting[j]->getvalue() > sorting[j + 1]->getvalue())
                        {
                            swap(sorting[j], sorting[j+1]);
                        }
                    }
                }
            }

            void checkkind (vector<Card *> kind)
            {
                int n;
                if(kind == hand1)
                {n = 0;}
                if(kind == hand2)
                {n = 1;}
                if(kind == crib)
                {n = 2;}

                for (unsigned j = 0; j < kind.size() - 1; ++j)
                {
                    if (kind[j]->getvalue() == kind[j+1]->getvalue())
                    {
                        switch (n)
                        {
                            case 0: tscore1 += 2;
                            case 1: tscore2 += 2;
                            case 2: tscorec += 2;
                        }

                        if (kind[j]->getvalue() == kind[j+2]->getvalue())
                        {
                            switch (n)
                            {
                                case 0: tscore1 += 4;
                                case 1: tscore2 += 4;
                                case 2: tscorec += 4;
                            }
                            if (kind[j]->getvalue() == kind[j+3]->getvalue())
                            {
                                switch (n)
                                {
                                    case 0: tscore1 += 6;
                                    case 1: tscore2 += 6;
                                    case 2: tscorec += 6;
                                }
                                cout << "4 of a kind = 12 points" << endl;
                                break;
                            }

                            else
                            {
                                cout << "3 of a kind = 6 points" << endl;
                                j += 2;
                            }
                        }

                        else
                            {
                                cout << "2 of a kind (pair) = 2 points" << endl;
                                ++j;
                            }
                    }
                }
            }

            



and the rest of it:

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
void setstartercard ()
            {
                startercard = pcardvector.back();
                pcardvector.pop_back();
            }

            void getscard ()
            {
                switch(startercard->getvalue())
                    {
                        case 1: cout << "Ace"; break;

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

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

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

                        default: cout << startercard->getvalue(); break;
                    }
                cout << " of " << startercard->getsuit() << endl;
            }

            void addscard ()
            {
                hand1.push_back(startercard);
                hand2.push_back(startercard);
                crib.push_back(startercard);
            }

            void check15 (vector<Card *> f15)
            {
                int card1; int card2;

                int n;
                if(f15 == hand1)
                {n = 0;}
                if(f15 == hand2)
                {n = 1;}
                if(f15 == crib)
                {n = 2;}

                for (unsigned j = 0; j < f15.size() - 1; ++j)
                {
                    int q = -1;
                    ++q;
                    for (unsigned h = 0; h < f15.size() - q; ++h)
                    {
                        switch (f15[j]->getvalue())
                        {
                        case 11: card1 = 10; break;
                        case 12: card1 = 10; break;
                        case 13: card1 = 10; break;
                        default: card1 = f15[j]->getvalue(); break;
                        }

                        switch (f15[j + h]->getvalue())
                        {
                        case 11: card2 = 10; break;
                        case 12: card2 = 10; break;
                        case 13: card2 = 10; break;
                        default: card2 = f15[j + h]->getvalue(); break;
                        }

                        if (card1 + card2 == 15)
                        {
                            switch (n)
                        {
                            case 0: tscore1 += 2;
                            case 1: tscore2 += 2;
                            case 2: tscorec += 2;
                        }
                            cout << "15 score: 2 points" << endl;
                        }
                    }
                }
            }

            void game()
            {


    shufflecards();
    dealcards();
    sorthand(hand1);
    cout << "player one's hand contains: " << endl; cout << endl;
    printing(hand1);
    cout << "player 1, type the number of the card you wish";
    cout << " to discard to the crib:" << endl;
    cout << endl;
    discarding(hand1);
    printing(crib);
    sorthand(hand1);
    printing(hand1);
    cout << "now your second card to discard:" << endl;
    cout << endl;
    discarding(hand1);
    sorthand(hand1);
    printing(hand1);
    sorthand(hand2);
    cout << "player two's hand contains: " << endl; cout << endl;
    printing(hand2);
    cout << "player 2, decide which card you will dicard first:"<< endl;
    cout << endl;
    discarding(hand2);
    sorthand(hand2);
    printing(hand2);
    cout << "now choose the second card you wish to place in the crib:" << endl;
    cout << endl;
    discarding(hand1);
    sorthand(hand2);
    printing(hand2);
    sorthand(crib);
    setstartercard();
    addscard();
    sorthand(hand1);
    sorthand(hand2);
    sorthand(crib);
    cout << "the starter card is: "; getscard(); cout << endl;
    printing(hand1);
    checkkind(hand1);
    check15(hand1);
    cout << "player 1 has: " << getscore1() << " points" << endl;
    cout << endl;
    printing(hand2);
    checkkind(hand2);
    cout << "player 2 has: " << getscore2() << " points" << endl;
    cout << endl;
            }
};
Topic archived. No new replies allowed.