C or operator can this be done somehow?

Asked By 30 points N/A Posted on -
qa-featured

Hey guys,

Can c++ or operator be done? The code is:


if((a ||b)==0)return1;
return0;
boolCircle2::contains(Line2l){
 
if((p1.distanceFrom(l.p1)||p1.distanceFrom(l.p2))<=r){
 return1;
 }
 return0;
}

Is the coding in the second piece the problem? Any help would be awesome.

SHARE
Answered By 15 points N/A #174391

C or operator can this be done somehow?

qa-featured

Hi Tony,
There seems to be problem in the first as well as second code.
In your code, you need to compare for Logical OR condition. Hence you need to write the expression as (a==0)||(b==0)
If you write it as ((a||b)==0), it implements that the logical OR of a & b is equal to 0.
Now, in the second code, you need to separately compare the value of 'r' with both, 'p1' and 'p2'. Hence the expression needs to be written as
If((p1.distanceFrom(1.p1)<=r)||(p1.distanceFrom(1.p2)<=r)), return 1;

Related Questions