Simple Windows (and maybe other OS’s) Console Color Randomizer (C++)

Google+ Pinterest LinkedIn Tumblr +

This article is part of a series of my articles containing snippets of C++ code that will perform various functions.Feel free to use them or modify them as needed, AS LONG AS YOU DO NOT RE-PUBLISH THEM.  Wheter you need an inspiration for a project, a way around a coding problem, or you are just curious feel free to check out the table of contents to my series right here.

/* Nesecary Includes:

# include   ( Nesescary in order to issue system commands ( i.e the color command) as well as use the rand and srand functions.  Used to issue a variety of C commands )

# include ( Needed to feed the srand function which in turn feeds pseudo random numbers to the rand function )

# include ( Needed to randomize and store results as well as store ths results of the randomization )

void randcolor ()   //needs string.h and stdlib.h and time.h
{
char all [17]=”0123456789ABCDEF”;
srand(time(NULL));
int foreground, background;
char color [1];
foreground = rand()+1;
background = rand()+1;
color [0]= all [foreground];
color [1]= all [background];
while (foreground==background)
{
foreground= rand()+1;
background = rand()+1;
color [1]= all [foreground];
color [2]= all [background];
}  
char command [12];
char command1[]=”color “;
strcpy (command, command1);
strcat (command, color);
system (command);
}

z z z z z z z z z z z z z z z z z z z
z Liked What You Saw? z
z Theres More Where z
z That Came From Here z
z z z z z z z z z z z z z z z z z z z

Share.

About Author

Leave A Reply