Thread: Problem with Visual C++ ( randomize function )!

  1. #1
    Registered User marCplusplus's Avatar
    Join Date
    Nov 2001
    Posts
    68

    Problem with Visual C++ ( randomize function )!

    Hi,

    I am trying to compile the following code using Visual C++ 6.
    However, it is returning the following errors:

    error C2065: 'randomize' : undeclared identifier
    error C2065: 'random' : undeclared identifier

    Here's the code:


    #include <iostream.h>
    #include <stdlib.h> // for randomize(), rand
    #include <time.h> // for randomize()
    #include <conio.h> // for getche()

    enum Suit { clubs, diamonds, hearts, spades };

    const int jack = 11; // from 2 to 10 are
    const int queen = 12; // integers without names
    const int king = 13;
    const int ace = 14;

    class card
    {
    private:
    int number; // 2 to 10, jack, queen, king, ace
    Suit suit; // clubs, diamonds, hearts, spades
    public:
    void init(int n, Suit s) // initialize card
    { suit = s; number = n; }
    void display() // display the card
    {
    if( number >= 2 && number <= 10 )
    cout << number;
    else
    switch(number)
    {
    case jack: cout << "J"; break;
    case queen: cout << "Q"; break;
    case king: cout << "K"; break;
    case ace: cout << "A"; break;
    }
    switch(suit)
    {
    case clubs: cout << 'c'; break;
    case diamonds: cout << 'd'; break;
    case hearts: cout << 'h'; break;
    case spades: cout << 's'; break;
    }
    } // end display()
    }; // end class card

    void main()
    {
    card deck[52]; // deck of cards
    int j = 0; // counts thru deck
    int num; // card number

    cout << endl;
    for(num=2; num<=14; num++) // for each number
    {
    deck[j].init(num, clubs); // set club
    deck[j+13].init(num, diamonds); // set diamond
    deck[j+26].init(num, hearts); // set heart
    deck[j++ +39].init(num, spades); // set spade
    }

    cout << "\nOrdered deck:\n";
    for(j=0; j<52; j++) // display ordered deck
    {
    deck[j].display();
    cout << " ";
    if( !( (j+1) % 13) ) // newline every 13 cards
    cout << endl;
    }

    randomize(); // seed random number generator
    for(j=0; j<52; j++) // for each card in the deck,
    {
    int k = random(52); // pick another card at random
    card temp = deck[j]; // and swap them
    deck[j] = deck[k];
    deck[k] = temp;
    }

    cout << "\nShuffled deck:\n";
    for(j=0; j<52; j++) // display shuffled deck
    {
    deck[j].display();
    cout << " ";
    if( !( (j+1) % 13) ) // newline every 13 cards
    cout << endl;
    }
    getch(); // wait for keypress
    } // end main


    What is the problem? :<
    What may I do to fix it?

    Regards,
    Marc
    No matter how much you know, you NEVER know enough.

  2. #2
    Registered User Strider's Avatar
    Join Date
    Aug 2001
    Posts
    149
    Probably because there is no randomize or random function. The proper syntax would be this:
    Code:
    srand(time(0)); // for seed based on current time
    
    int k = 1 + rand() % 52; // for random number 1 to 52
    David
    One Ring to rule them all, One Ring to find them,
    One Ring to bring them all and in the darkness bind them
    In the Land of Mordor where the Shadows lie.

  3. #3
    Registered User marCplusplus's Avatar
    Join Date
    Nov 2001
    Posts
    68
    Thanks,

    Actually, I found it in a book and since it hasn't covered randomize functions yet, it said not to worry about them for now.
    However, it said that they would only work well with the Borland Compiler.

    Thanks once again,
    Marc
    No matter how much you know, you NEVER know enough.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  3. Replies: 6
    Last Post: 03-02-2005, 02:45 AM
  4. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM
  5. MS Visual C++ 6 wont include vector.h in a header file
    By bardsley99 in forum C++ Programming
    Replies: 9
    Last Post: 11-06-2003, 12:05 PM