First Card Shuffling Program

Hello Everyone,
I am trying to get this Card Shuffling and Dealing program working. I am having an issue with my moreCards(), dealCard() functions and how to get them to work within the main program. Below I posted my source code for the main program and the implementation of my DeckOfCard functions. Any help would be greatly appreciated. Thanks

Mathew

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


#include "stdafx.h"
#include "deckofcards.h"
#include <string>
#include <cstdlib>
#include <iomanip>
#include <ctime>

using namespace std;

DeckOfCards deck;
int cardLocation = 0;
const int numFace = 13;
const int numSuit = 4;
const int numCard = 52;

 
DeckOfCards::DeckOfCards() // this function creates a deck and is the constructor
{
	for (int f = 0; f < numFace; f++)
		for (int s = 0; s < numSuit; s++)
		{
		Card card(f, s);
		deck.push_back(card);
		cardLocation++;
		}
} // end DeckOfCards constructor


//=================================================================================
//
//
//
//
//
//=================================================================================

void DeckOfCards::shuffle()
{
	for (int i = 0; i < numCard; i++)
	{
		marker = rand() % numCard;
		Card holdCard = deck[marker];
		deck[marker] = deck[i];
		deck[i] = holdCard; 
	}

}// end function shuffle

//=================================================================================
//
//
//
//
//
//=================================================================================

void DeckOfCards::dealCard()
{
	while (cardLocation > 0)
	{
		cardLocation--;
		Card returnCard = deck[cardLocation];
		returnCard.toString();
		
	}

}// end function dealCard

//=================================================================================
//
//
//
//
//
//=================================================================================

void DeckOfCards::displayCards()
{
	for (int d = 0; d < numCard; d++)
	{
		cout << setw(19) << deck[d].toString();
		if ((d + 1) % 4 == 0)
			cout << endl;
	}

} // end function displayCards

//=================================================================================
//
//
//
//
//
//=================================================================================

int DeckOfCards::size()
{
	return deck.size();
	cout << " The deck size is " << size() << endl;

}

//=================================================================================
//
//
//
//
//
//=================================================================================

bool DeckOfCards::moreCards()
{
	int size = deck.size();
	if (size == 0)

		return false;  // no cards left in the deck
	else
 		return true; // card are left in the deck
	
}



Last edited on
Here is the main Program code right now.

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
#include "stdafx.h"
#include <iostream>
#include "card.h" // header file to include Card class member functions
#include "deckofcards.h" // header file to include DeckOfCards member functions
#include <string> // Basic C++ string library

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{

	DeckOfCards deck;
	deck.dealCard();
	deck.shuffle();
	deck.displayCards();

	system("pause");

	cout << endl << endl;

	deck.shuffle();
	deck.displayCards();

	system("pause");

	cout << endl << endl;

	deck.size();
	deck.shuffle();
	deck.dealCard();
	deck.moreCards();

	system ("pause");

	return 0;
} // end main function 
Topic archived. No new replies allowed.