Check value of struct with Multiple Bools

Hello I have a function the takes the following data structure as an argument

typedef struct{
bool var1;
bool var2;
bool var3;
bool var4;
}boolData;

I need to check if 3 of any combination of the bool variables are true. Is there a clean way to do this besides complicated nested if statements.

Thanks,
Ford
if (d.var1+d.var2+d.var3+d.var4==3)...
Thank you for the quick reply. Is there any way that I can determine which of the 3 data members is true without nested if statements?
1
2
3
const bool* vars[]={&var1,&var2,&var3,&var4};
const int varCount=sizeof(vars)/sizeof(*vars);
for (int i=0;i<varCount;i++)if (*vars[i])...;
Thank you. That does it for me. One last question just for my understanding. Why did you choose to make it an array of pointers versus just an array of values?
Out of habit. When you're dealing with complex objects or want to modify some of the original values, you don't want to make any copies. But in this case, it would work just as well.
Topic archived. No new replies allowed.