### Shuffle and Deal Deck of Cards

Can someone look over my code and see if it looks okay. It won't compile for me and I can't figure out what is wrong. It's suppose to randomly assign numbers to an array to simulate a deck and then shuffle them and then deal (output) 13 hands of 4 cards to make sure the random number generator works.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103`` ``````#include using namespace std; void display(int arr[], int count); class DeckOfCards { public: DeckOfCards(); void shuffle(); int dealCard(); private: int deck[52]; int nextCard; unsigned int pseudoRand(); }; unsigned int DeckOfCards::pseudoRand() { unsigned int x; x = 22695477 * x + 1; x = x%52; return x; } DeckOfCards::DeckOfCards() { pseudoRand(x); for(int i=0;i<52;i++) { deck[i]=pseudoRand()%52; } shuffle(); nextCard=0; } void DeckOfCards::shuffle() { int temp, j; for(int i=51;i>0;i--) { j=pseudoRand(); temp=deck[i]; deck[i]=deck[j]; deck[j]=temp; } return; } int DeckOfCards::dealCard() { nextCard++; if(nextCard<=52) return deck[nextCard-1]; else return -1; } int main() { DeckOfCards deck; int hand[4]; for(int i=0;i<13;i++) { for(int j=0;j<4;j++) { hand[j]=deck.dealCard(); } display(hand,4); } return 0; } void display(int arr[],int count) { cout<
It would be easier if you posted the compiler output in full.

return statements are not needed for void functions.
Last edited on
This is the error message I keep getting:

cards.cpp: In function ‘void display(int*, int)’:
cards.cpp:76:15: error: expected initializer before ‘<’ token
cards.cpp:100:1: error: expected primary-expression at end of input
cards.cpp:100:1: error: expected ‘;’ at end of input
cards.cpp:100:1: error: expected primary-expression at end of input
cards.cpp:100:1: error: expected ‘)’ at end of input
cards.cpp:100:1: error: expected statement at end of input
cards.cpp:100:1: error: expected ‘}’ at end of input
This isn't the full output. We don't actually need the full output, but the first few lines of it would be good. The last lines... not so much.
Last edited on
Nevermind I think I figured it out. I missed a part when i was reading the problem. I was suppose to use the class RandomVariable that we used in another problem.
Topic archived. No new replies allowed.