0

I'm in a little over my head, and I'm not sure what this error means or what to do about it. Here's my code:

class player::deck
{
    public:
        vector<int> deck;
        int draw(){
            int card = srand(time(NULL)) % deck.size();
            deck.erase(deck(begin)+card);
            return card;
        }
};

What I'm trying to do is make a deck for each player. Cards represented by integers (0 is card 0, 1 is card 1, etc.).

And here's the error:

/home/ubuntu/workspace/try3/main.cpp: In member function ‘int player::deck::draw()’:                                                                                                             
/home/ubuntu/workspace/try3/main.cpp:27:54: error: invalid operands of types ‘void’ and ‘std::vector<int>::size_type {aka long unsigned int}’ to binary ‘operator%’                              
         int card = srand(time(NULL)) % deck.size();                                                                                                                                         
                                                  ^                                                                                                                                          
/home/ubuntu/workspace/try3/main.cpp:28:34: error: no match for call to ‘(std::vector<int>) (<unresolved overloaded function type>)’                                                             
         deck.erase(deck(begin)+card);                                                                                                                                                       
                              ^        

Any help would be tremendously appreciated. If I'm in the wrong place or I'm using the site incorrectly, please let me know.

1 Answers1

2

You want to do this:

srand(time(NULL));
int card = rand() % deck.size();

srand: Initialize random number generator

rand: Generate random number

anukul
  • 1,922
  • 1
  • 19
  • 37