I'll do my best to be as clear as possible about what I'm trying to do. In short, I'd like to know if a switch statement can check multiple variables simultaneously (I have a feeling it can't, but I'd like to confirm).
If it can't, can someone recommend a way around doing this without doing a million if statements?
I wrote a "Color" class that does all sorts of conversions, and one of the conversions it does is between the HTML standard color words and their corresponding RGB values. I wrote a huge if/else series (since switch statements can't process strings, I believe) that checks the word and if it's one of the HTML words it'll return a map with the RGB values at RGB, RGB, and RGB
Now, I'd like a way to do the opposite...given 3 doubles - R, G, and B...the computer will be able to give the respective word if it exists, otherwise the default would be to 'cout << "The values you gave does not correspond with a color word" << endl;'
I'm hoping for something that would act similar to this:
string Color::RGB2WORD(double R , double G, double B)
{
switch(R,G,B)
{
case 255, 250, 245:
return "someword";
...etc...etc...
}
}
I feel this *would* be easier to code if it was possible or if there was some similar way to do it, than to write a long series of if statements as the respective if statements would be:
if(R==255 && G==250 && B==245)
return "someword";
else if(.........................)
....
I feel it'd be easier to work with, and I'm also curious what other suggestions I may get regarding this. I know it's an unusual request to have a switch compare multiple variables, and would be very rarely used, but I like trying something different and seeing what alternatives there are.
If it really comes down to it, I can write the if/else statements. But there are 183 different words to return and if I can simplify it for copy/paste or otherwise just a little bit, it'd be awesome
I guess I *could* write a script that could attempt to automate it though if needed. But it'd be somewhat of a one-time deal and about an hour or so of copy/paste/edit otherwise
PS: Sorry for the rambling above...kind of got off track on some alternatives of my own lol
Cliffs: Looking for (ideally) a switch statement that can compare multiple variables or an alternative (preferably not if/else, as I know it's a viable alternative...but am curious what else may exist, or other ways to?)
Thanks in advance!
-Josh