Question: C++ only Generating random colors Write a program that generates a different list of 100 random RGB color values using hexadecimal notation. The program should

C++ only

Generating random colors

Write a program that generates a different list of 100 random RGB color values using hexadecimal notation. The program should write something like the following into cout.

324AF3

6A3125

... 98 additional RGB values

To solve this problem you need to generate strings with 6 characters where each character is randomly chosen from the following set of symbols.

{ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }

To make the choice random, you need to use the modulo operator (%). Specifically, use the expression rand()%16 to get a random integer between 0 and 15.

You are required to solve this problem by defining a loop within a loop. In fact, with the language features of C++ covered until this point, the solution to this problem requires a loop within a loop. If you know how to solve the problem without a nested loop, then you are required to solved it with a nested loop anyway, because learning how to write nested loops is the main learning objective of this exercise.

The program should generate a different list of color values each times it runs. To get this result, you need to seed the random number generator with a new value each time the program runs. One easy way to do this is to use the current time in seconds as a seed value. The following code shows how to do this.

#include

...

int main()

{

srand(time(0));

...

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!