1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

random color and size function?

Discussion in 'C' started by compscichick, Sep 9, 2010.

  1. compscichick

    compscichick New Member

    Joined:
    Sep 7, 2010
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    I have a marble.h file, and in the main.cpp file I need to have it call and object( a marble in this case) with a random color (either yellow, red, blue or green) and a random size (small=1, medium=2, or large=3)

    then it outputs as as (color,size)

    i really have no idea where to start.

    the header file already declares int random_color() and in random_size() as well as enum Color (yellow, red,blue,green) and enum Size (small, medium, large)
     
  2. LordN3mrod

    LordN3mrod New Member

    Joined:
    Sep 4, 2010
    Messages:
    22
    Likes Received:
    11
    Trophy Points:
    0
    Occupation:
    Software Developer
    Location:
    Yerevan, Armenia
    Well you could do the following

    Code:
    #include <ctime>  //for time
    #include <cstdlib> //for srand and rand
    
    int main()
    {
       std::srand(std::time(0))
       Color color = (Color) (rand()%4);
       Size size = (Size)( rand()%3);
       CreateMyRandomObject(color, size);
    }
    
    google about srand and rand for more info
     

Share This Page