
How do I determine if *exactly* one boolean is true, without type conversion?
1 Expert Answer

Patrick B. answered 07/14/19
Math and computer tutor/teacher
You have a list of N boolean variables hopefully in an array....
N is a positive integer
boolean boolArray[N];
int hitCount=0;
for (iLoop=0; iLoop<N; iLoop++)
{
if (boolArray[iLoop]) { hitCount++; }
if (hitCount>1)
{
break;
}
}
if (hitCount==1)
{
// output that there is only one true boolean var in the array
}
else
{
// putput there is more than one true boolean var in the array
}
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Patrick B.
You have a list of boolean variables , hopefully in an array; Just write a for loop counting how many are true07/14/19