Hello i am new the the programing sene and im trying to create a program for my help with my html and i am stuck! I can get basic HEX code from like CC to 204 dec. but i cant go backwards? and i want to be able to tell the computer that i want 80% red 40% blue and 20% green then it tells me in HEX what that is... but im stumped could any one help me?
heres what i have so far

#include <cstdlib>
#include <iostream>
#include <string>
#include <math.h>

using namespace std;

int main(int argc, char *argv[])
{
    int z; // Percentage Red
    float redhex; // The hex equivilent of Red
    float redrightnib; // This is the right nib of red
    float redleftnib; // This is the left nib of red
    int x; // Percentage Green
    float greenhex; // The hex equivilent of Green
    float greenleftnib; // This is the left nib of green
    float greenrightnib; // This is the right nib of green
    int y; // Percentage Blue
    float bluehex; // The hex equivilent of Blue
    float blueleftnib; // This is the left nib of blue
    float bluerightnib; // This is the right nib of blue
    
        
    cout << "Tell Me The Color You Want in Percentage Form 0-100" << endl;
    cout << "Tell Me The Red Percentage First" << endl;
    cin >> z;
        if (z>=0, z<=100)
           {
            cout << "Ok Good Now give me the Green Percentage" << endl;
            cin >> x; // The Color Green in persentage            
                if (x>=0, x<=100)
                {
                cout << "Now the Blue Percentage" << endl;
                cin >> y;
                    if (y>=0, y<=100)
                       {
                       cout << "Ok In Hexcode " << z<< "%," << x << "%," << y << "%" << " Equals" << endl;
                         redhex = (z*255)/100;
                         redhex/16
                         //equation????
                         
                 
                         greenhex = (x*255)/100;
                        
                         //equation????
                 
                         bluehex = (y*255)/100;
                         
                         //equation????
                 
                         cout << "#" << redleftnib << redleftnib << ", " << blueleftnib << bluerightnib << ", " << greenleftnib << greenrightnib << endl;
                         }
                     else
                         {
                         cout << "No!" << endl;
                         }
                 }
                 else
                     {
                     cout << "I said 0-100!" << endl;
                     }                             
            }
        else
            {
            cout << "Did you Even Read The Directions" << endl;
            }
    system("PAUSE");
    return EXIT_SUCCESS;
}

can u pls explain me the logic for converting from rgb to hex? ie tell me what will be the equivalent of 80% red 40% green and 20% blue and how to get it exactly(the logic or formulat i suppose) then i may be able to help...and what r those nib variables ... u havent used them in ur pgm at all...they contain garbage values

Beuls

try this code

#include <cstdlib>
#include <iostream>
#include <string>
#include <math.h>
#include <conio.h>

using namespace std;
char* hexc(int);

int main(int argc, char *argv[])
{
int z; // Percentage Red

int x; // Percentage Green

int y; // Percentage Blue

char red[50],green[50],blue[50];


cout << "Tell Me The Color You Want in Percentage Form 0-100" << endl;
cout << "Tell Me The Red Percentage First" << endl;
cin >> z;
if (z>=0, z<=100)
{
cout << "Ok Good Now give me the Green Percentage" << endl;
cin >> x; // The Color Green in persentage 
if (x>=0, x<=100)
{
cout << "Now the Blue Percentage" << endl;
cin >> y;
if (y>=0, y<=100)
{
cout << "Ok In Hexcode " << z<< "%," << x << "%," << y << "%" << " Equals" << endl;
strcpy(red,hexc(z));
strcpy(green,hexc(x));
strcpy(blue,hexc(y));
cout<<"#"<<strrev(red)<<strrev(green)<<strrev(blue)<<endl;
}
else
{
cout << "No!" << endl;
}
}
else
{
cout << "I said 0-100!" << endl;
} 
}
else
{
cout << "Did you Even Read The Directions" << endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}


char* hexc(int h)

	{

	int dum,ab,i,r;
	char arr[50]=" ";
	  	dum=h;
		ab=0;
		for (i=0;dum>=16;dum=dum/16,i++)
		{
			r=dum%16;
xx:
			switch(r)
			{
			case 0:arr[i]='0';break;
			case 1:arr[i]='1';break;
			case 2:arr[i]='2';break;
			case 3:arr[i]='3';break;
			case 4:arr[i]='4';break;
			case 5:arr[i]='5';break;
			case 6:arr[i]='6';break;
			case 7:arr[i]='7';break;
			case 8:arr[i]='8';break;
			case 9:arr[i]='9';break;
			case 10:arr[i]='A';break;
			case 11:arr[i]='B';break;
			case 12:arr[i]='C';break;
			case 13:arr[i]='D';break;
			case 14:arr[i]='E';break;
			case 15:arr[i]='F';break;
			}
		}
			
		if (ab==0)
		{
			ab=1;
			r=dum;
			goto xx;
		}
		
		
		return arr;
	}

THanks beuls worked like a charm. I havent yet learned about case statements yet so im not quite sure why it works but ill be damnd that it does.

case is similar to if statement ; it is a conditional control statement for checking multiple conditions

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.