A truly amazing result!!!

 

Code:

void DebugInfo()
{
   int a=23;
   int s=20;
   int f=1;
   // Исходное условие
   bool r1 = a>= s && a<= f && s<= f || ( a>= s || a<= f) && s> f;
   // Дальше пошли извращения
   bool r2 = a>= s && a<= f && s<= f;
   bool r3 = ( a>= s || a<= f) && s> f;
   bool r4 = r2 || r3;
   // Вывод
   Print ( r1+" "+ r2+" "+ r3+" "+ r4);
   // Результат: 0 0 1 1. А должно быть: 1 0 1 1.
}

Now a question for you to ask: who is glitching me or MQL4???

Thanks:)

 

Truly delightful!


It looks like you could make a quick buck on this one!

 

what are you not satisfied with?
yes=1, no=0,

a<=f does not fulfil

==right answer

 
Korey >> :

what are you not satisfied with?
yes=1, no=0,

a<=f is not fulfilledc

== right answer

But it does (a>=s || a<=f) && s>f

 
WWer писал(а) >>

But (a>=s || a<=f) && s>f

Then the brackets should be

 
Vinin >> :

You should have put brackets

Why? || has a higher priority than &&

 
(a>=s || a<=f) - 1 || 0 = 1
(a>=s || a<=f) && s > f - 1 && 1 = 1

In fact, you should explicitly bracket it. I already fell for it once.

WWer >>:

Зачем? У || большый приоритет чем у &&

so specify it in the code, so the script can understand it =)


 
Korey писал(а) >>

what are you not happy with?
>> yes=1, no=0,

a<=f does not fulfil

==f is correct

The answer is either correct, or it's just a very strange rule in MQL4, or the logical operations are performed by very strange rules. It doesn't look like C/C++ or anything else. I even translated it into JavaScript:

var a=23;
var s=20;
var f=1;
// Исходное условие
var r1 = a>=s && a<=f && s<=f || (a>=s || a<=f) && s>f;
// Дальше пошли извращения
var r2 = a>=s && a<=f && s<=f;
var r3 = (a>=s || a<=f) && s>f;
var r4 = r2 || r3;
// Вывод
WScript.Echo(String(r1)+" "+String(r2)+" "+String(r3)+" "+String(r4));
Result: true false true true true
 
WWer писал(а) >>

Why? || has a higher priority than &&

Conversely, && has a higher priority than ||.

 
nen >> :

Conversely, && has a higher priority than ||

IN MQL4 ? Possibly, but it should be.

 

Not at all ! The "or"(||) takes precedence here - unambiguously !

If there are no parentheses, then || is executed first, and then &&

Therefore brackets must be placed in the appropriate places.

Reason: