if condition with && doesn't work

To add comments, please log in or register
cpr
26
cpr  

I have a problem with if condition and && operator.

This simple code alway give "true" as result, when must give "false". Any idea about the problem? I'm getting crazy....

Thanks in advace

   double a=3;
   double b=5;
   bool c=true;
   bool d=false;
   
   if ((a<b)&&(c=true)&&(d=true))
   {Alert("TRUE");}
   else
   {Alert("FALSE");}
   

Mladen Rakic
110160
Mladen Rakic  
CPR:

I have a problem with if condition and && operator.

This simple code alway give "true" as result, when must give "false". Any idea about the problem? I'm getting crazy....

Thanks in advace

You are using assignment instead of comparison operator for booleans

Change the code to this

   double a=3;
   double b=5;
   bool c=true;
   bool d=false;
   
   if ((a<b)&&(c==true)&&(d==true))
   {Alert("TRUE");}
   else
   {Alert("FALSE");}

and all will be OK

To add comments, please log in or register