Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   random color and size function? (http://www.go4expert.com/forums/random-color-size-function-t23261/)

compscichick 9Sep2010 23:27

random color and size function?
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)

LordN3mrod 9Sep2010 23:48

Re: random color and size function?
Well you could do the following


#include <ctime>  //for time
#include <cstdlib> //for srand and rand

int main()
  Color color = (Color) (rand()%4);
  Size size = (Size)( rand()%3);
  CreateMyRandomObject(color, size);

google about srand and rand for more info

All times are GMT +5.5. The time now is 17:45.