Okay, I think I got this working pretty much like it's supposed to. The one thing that is sort of stumping me, however, is the shuffle function. To shuffle, I was thinking of just allowing all of the cards to be picked from again. Any advice on a good way of doing this? I was thinking about creating another for loop to just re-populate the array with 52 cards, but that just does not seem right for some reason. Also, after I do shuffle the cards, would I just do something like
Code:
a.shuffle();
for(int i =1; i < 6; i++) // using same for loop as first time I dealt first hand ??????
{
the_card = a.deal();
cout << the_card << endl;
}
for(int j = 1; j < 6; j++) //using same for loop as the first time I dealt a second hand???
{
the_card = a.deal();
cout << setw(15) << the_card << endl;
}
Here is my whole program, I am hoping someone can look it over and see if I did things like the directions specified, etc. Thanks
Code:
#include <iostream>
#include<iomanip>
#include<ctime>
using namespace std;
class Cards
{
private:
int deck[52];
int card ;
public:
Cards(); //Constructor
int deal();
void shuffle();
};
Cards::Cards() //constructor
{
card = 51;
srand(time(NULL));
}
int Cards::deal()
{
int i;
int deck[52];
int the_card;
int suit, value;
int randcard = 1 + rand()% 52;
for (i = 0; i < 52; i++)
{
deck[i]=i;
}
suit = deck[randcard] % (4+1) * 100;
value = deck[randcard] % 13 + 1;
deck[card] = deck[randcard];
deck[card] = deck[card-1];
the_card = suit+value;
return the_card;
}
void shuffle ()
{
}
int main()
{
int the_card;
Cards a;
for(int i =1; i < 6; i++)
{
the_card = a.deal();
cout << the_card << endl;
}
for(int j = 1; j < 6; j++)
{
the_card = a.deal();
cout << setw(15) << the_card << endl;
}
cin.get();
return 0;
}