celestinebroke

Random Color Syntax

Jan 19th, 2022 (edited)
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include<iostream>
  2. #include<stdlib.h>
  3. #include<time.h>
  4. using namespace std;
  5.  
  6. void rgb_color_code(int rgb[]);
  7.  
  8. void rgb_color_code(int rgb[])
  9. {
  10.   int i;
  11.   for(i=0;i<3;i++)
  12.   {
  13.     rgb[i]=rand()%256;
  14.   }
  15. }
  16.  
  17. int main()
  18. {
  19.   int rgb[3];
  20.   char hex[6];
  21.     srand(time(0));
  22.    
  23.     //RGB color code
  24.     rgb_color_code(rgb);
  25.   cout<<"Random RGB color code: ";
  26.   cout<<"rgb(";
  27.   for(int i=0;i<3;i++)
  28.   {
  29.     cout<<rgb[i];
  30.     //to seperate red, blue, color values by a comma( no comma for last value)
  31.     if(i!=2)
  32.     {
  33.       cout<<", ";
  34.     }
  35.   }
  36.   cout<<")"<<endl;
  37.  
  38.   return 0;
  39. }
Add Comment
Please, Sign In to add comment