random color and size function?

compscichick's Avatar, Join Date: Sep 2010
Light Poster
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)
0
LordN3mrod's Avatar, Join Date: Sep 2010
Go4Expert Member
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