Random Shuffle Error

I'm trying to use the random_shuffle but for some reason I'm getting an error and I can't work out why. Could someone have a look please.

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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
 include "pch.h"
#include <iostream>
#include <algorithm> //for random_shuffle

using namespace std;
#define NUMBER_OF_CARDS 52


enum SUIT {HEARTS, DIAMONDS, CLUBS, SPADES};

struct Card {
	SUIT suit; // H, D, S, C
	int value; // A, 2, 3, 4, 5, 6, 7, 8, 9, 10
	int score; // A = 1 2 = 2, Q = 10

};

Card Pack[NUMBER_OF_CARDS];

void SetupPack();
void SetupHearts();
void SetupDiamonds();
void SetupClubs();
void SetupSpades();
char Menuchoice;
void Play(); //play blackjack

void Menu();
void NewGame();
void Help();
void Exit();
void Shuffle();





int main()
{
	Menu();
}

void Menu()
{
	do
	{
		cout << endl;
		cout << "Welcome to Blackjack" << endl;
		cout << "1. New Game - Press N" << endl;
		cout << "2. Help - Press H" << endl;
		cout << "3. Exit - Press X" << endl;

		cin >> Menuchoice;

		if ((Menuchoice == 'N') || (Menuchoice == 'n'))
		{
			cout << endl;
			NewGame();
		}

		else if ((Menuchoice == 'H') || (Menuchoice == 'h'))
		{
			cout << endl;
			Help();

		}


		else if ((Menuchoice == 'X') || (Menuchoice == 'x'))
		{
			cout << endl;
			Exit();
		}
		else {
			cout << endl;
			cout << "Oops wrong letter, please try again" << endl;
		}


	} while (Menuchoice != 'X');

}

void NewGame()
{
	cout << "New Game selected" << endl;
	Play();
	
}



void Help()

{
	cout << "Help " << endl;
	cout << "Instructions:" << endl; 
	cout << "The cards are shuffled and each player is dealt a card" << endl;
}



void Exit()
{
	cout << "Exiting.." << endl;
	Menu();
}



void Play()

{

	
	


	
	cout << "do you want to stick or twist?" << endl;
		


}


void SetupPack()
{
	SetupHearts();
	SetupDiamonds();
	SetupClubs();
	SetupSpades();
}

void SetupHearts()
{
	for (int loop = 0; loop <= 12; loop++)
	{
		Pack[loop].suit = HEARTS;
		Pack[loop].value = loop + 1;
		Pack[loop].score = loop + 1;

	}
	//score for Jack, Queen, King
	Pack[10].score = 10;
	Pack[11].score = 10;
	Pack[12].score = 10;
}

void SetupDiamonds()
{
	for (int loop = 13; loop <= 25; loop++)
	{
		Pack[loop].suit = DIAMONDS;
		Pack[loop].value = loop + 1 - 13; //need to take away 13 so it shows 1-12 
		Pack[loop].score = loop + 1 - 13;

	}
	//score for Jack, Queen, King
	Pack[23].score = 10;
	Pack[24].score = 10;
	Pack[25].score = 10;
}


void SetupClubs()
{
	for (int loop = 26; loop <= 38; loop++)
	{
		Pack[loop].suit = CLUBS;
		Pack[loop].value = loop + 1 - 26; // need to take away 26 so it shows 1 - 12
		Pack[loop].score = loop + 1 - 26; // need to take away 26 so it shows 1 - 12

	}
	//score for Jack, Queen, King
	Pack[36].score = 10;
	Pack[37].score = 10;
	Pack[38].score = 10;
}

void SetupSpades()
{
	for (int loop = 39; loop <= 51; loop++)
	{
		Pack[loop].suit = SPADES;
		Pack[loop].value = loop + 1 - 39; // need to take away 39 so it shows 1 - 12
		Pack[loop].score = loop + 1 - 39; // need to take away 39 so it shows 1 - 12

	}
	//score for Jack, Queen, King
	Pack[49].score = 10;
	Pack[50].score = 10;
	Pack[51].score = 10;
}

void displayPack()
{
	for (int loop = 0; loop < NUMBER_OF_CARDS; loop++)
	{
		cout << "Suit = " << Pack[loop].suit;
		cout << "Score = " << Pack[loop].score;
		cout << "Value = " << Pack[loop].value;
		cout << endl;
	}
}

	void Shuffle()
	{
		random_shuffle(Pack[0], Pack[51]);


	}
	

	
What exactly is the error?

By the way did you read any documentation for this depreciated function?

Severity Code Description Project File Line Suppression State
Error C2794 'difference_type': is not a member of any direct or indirect base class of 'std::iterator_traits<_RanIt>' BLACKJACKNEW c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.15.26726\include\algorithm 2597



Severity Code Description Project File Line Suppression State
Error C2938 '_Iter_diff_t<Card>' : Failed to specialize alias template BLACKJACKNEW c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.15.26726\include\algorithm 2597


Severity Code Description Project File Line Suppression State
Error C2903 '_Rng_from_urng': symbol is neither a class template nor a function template BLACKJACKNEW c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.15.26726\include\algorithm 2597


Severity Code Description Project File Line Suppression State
Error C2514 'std::_Rng_from_urng': class has no constructors BLACKJACKNEW c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.15.26726\include\algorithm 2597

There should be more errors, errors that point to your code, however it looks like you didn't look at any documentation for the function.

Do you realize that that function requires iterators, not values for it's parameters?

Do you know the difference between an iterator and a value.

You can simulate iterators by using pointers, ie: random_shuffle(Pack, Pack + 52);

You really should try to eliminate the global variables and pass the variables to and from your functions as required.

Right I see. I was told to use the random_shuffle and to input the values like I had. So if I use
1
2

random_shuffle(Pack, Pack + 52);


will that do what I want it to do?

Thank you.
What happened when you made the changes and compiled and ran your program?

You really really should find an read the documentation for that standard function, the documentation should answer most of your questions.

I haven't managed to work out how to show one of the cards after they have been shuffled, so it compiles but I don't know if it shuffles, unless it should show something without me showing a card? I'm just confused at the moment.
Last edited on
Okay, but it is compiling so now you have a different problem.

Where are you calling any of your "setup" functions, the random_shuffle function, and the display function?

from the Play() function. I've put the random_shuffle function inside the Play() but I haven't figured out how to display 2 cards to both the player and the dealer
Last edited on
By the way since you seem so confused I suggest you start simpler.

Start by calling your "setup" function, followed by your "display" function followed by your "shuffle" function.

Something like this perhaps?

1
2
3
4
5
6
7
8
9
10
11
int main()
{
    //Menu();
    SetupPack();
    displayPack();

    std::cout << "\n\nShuffling ...\n\n";
    
    Shuffle();
    displayPack();
}


You will probably want to get your "display" function to actually display the name of the suit and the name of the card instead of the the semi-meaningless numbers.

Suit = 0Score = 10Value = 13

Those numbers really don't make much sense to anybody but maybe you.



But I don't know how I can get it to display 2 cards for both the player and the dealer? because when i use displayPack(); it displays the whole set of cards. I just want to give the dealer and the player 2 cards each.
So what does that have to do with any of the problems you've asked previously?

You're totally lost so start simpler. Start by insuring that your "deck" holds the proper cards after you've initialized that horrible global variable and that the "shuffle" actually works. Then if you need help re-post your current code and ask specific questions based on the code you provide.

By the way most of your functions are not really doing anything useful, you still need to implement the functionality those functions require.

Topic archived. No new replies allowed.