Please help. My grades/rest of life depends on it!

Please help! i am making a deck class that has to be able to print the current deck, draw a card, and shuffle the deck. I really need help with the shuffling portion. Here is my code so far:

#include <iostream>
#include <time.h>
#include <stdlib.h>

using namespace std;

class Card
{
public:
Card();
void createcard(int, int);
void createcards();
int usedcard();
int newcard();
int returntovalue();
int returntosuit();

private:
int avalue;
int asuit;
int present;
};
Card::Card()
{
present=true;
}
void Card::createcard(int value, int suit)
{
avalue=value;
asuit=suit;
}
void Card::createcards()
{
if (avalue==0)
{
cout << "Ace " << "Of ";
}
else if (avalue==10)
{
cout << "Jack " << "Of ";
}
else if (avalue==11)
{
cout << "Queen " << "Of ";
}
else if (avalue==12)
{
cout << "King " << "Of ";
}
else
{
avalue=avalue+1;
cout << avalue << " " << "Of ";
avalue=avalue-1;
}
if (asuit==0)
{
cout << "Hearts" << endl;
}
else if (asuit==1)
{
cout << "Diamonds" << endl;
}
else if (asuit==2)
{
cout << "Clubs" << endl;
}
else if (asuit==3)
{
cout << "Spades" << endl;
}
}
int Card::usedcard()
{
present=false;
}
int Card::newcard()
{
present=true;
}
int Card::returntovalue()
{
return present;
}
int Card::returntosuit()
{
return asuit;
}

class Deck
{
public:
Deck();
void createdeck();
void printcurrentdeck();
void shuffle();
void drawcard();
void makefalse();
void returncard();

private:
Card totalcards[52];
Card shuffler[52];
Card hand[1];

};
Deck::Deck()
{
}
void Deck::createdeck()
{
for (int a=0; a<13; a++)
{
for (int b=0; b<4; b++)
{
totalcards[a+b*13].createcard(a,b);
}
}
}
void Deck::printcurrentdeck()
{
for (int i=0; i<52; i++)
{
if (totalcards[i].returntovalue()==true)
{
totalcards[i].createcards();
}
}
}
void Deck::shuffle()
{

}
void Deck::drawcard()
{
int i=0;
int valid=0;
while (valid==0)
{
if (totalcards[i].returntovalue()==true)
{
hand[0]=totalcards[i];
valid=1;
totalcards[i].usedcard();
}
i++;
}
valid=0;
hand[0].createcards();
}
void Deck::makefalse()
{
}
void Deck::returncard()
{

}
int main()
{
int number;
Deck myDeck;
myDeck.createdeck();
cout << "Enter a command:" << endl;
cout << "1 to show current deck" << endl;
cout << "2 to shuffle" << endl;
cout << "3 to draw a card" << endl;
cout << "4 to end program" << endl;
while (number!=4)
{
cin >> number;

if (number==1)
{
myDeck.printcurrentdeck();
}
if (number==2)
{
myDeck.shuffle();
}
if (number==3)
{
myDeck.drawcard();
}
if (number==4)
{
break;
}
}
}
Last edited on
Ok... If SOOO much depends on this code, why don't you put some effort into. Hell, put some effort into asking for help too! What do you want the program to do? What does it actually do? What part of the code do you think is the problem? Use [code]code here[/code] tags too, for readability.
More conducive to that end (readability) would be an ounce or two of indentation, lol.
Download and read How to Think like a Computer Scientist CPP edition.
Topic archived. No new replies allowed.