Many conditions

Many conditions - Poruke

#1 Objavljeno: 17. 8. 2021. 04:30:44
Vasia

Vasia

0 svidjanja u 17 postova.

Grupa: User

Здравствуйте.
Столкнулся со следующей проблемой: есть несколько условий, необходимо, чтобы при заданных значениях правильно бралось значение "а".
У меня почему-то игнорируется последнее условие - p0, то есть, в моем случае должно быть а=4, а программа выдает а=3.
Что я сделал не так?
example.jpg
proba.sm (11,3 KiB) preuzeto 1257 put(ova).
#2 Objavljeno: 17. 8. 2021. 04:47:43
sergio

sergio

127 svidjanja u 342 postova.

Grupa: User

I don't see error in Smath as the reports indicated in the third "If" are all verified and therefore does not even pass to the fourth "IF". Maybe you should add that P0 = 0 (or something else).
P.S. I also point out an OR in the fourth "IF" while all the others are AND: it could be an oversight
sergio
#3 Objavljeno: 17. 8. 2021. 04:54:56
Vasia

Vasia

0 svidjanja u 17 postova.

Grupa: User

Wrote

I don't see error in Smath as the reports indicated in the third "If" are all verified and therefore does not even pass to the fourth "IF". Maybe you should add that P0 = 0 (or something else).
P.S. I also point out an OR in the fourth "IF" while all the others are AND: it could be an oversight
sergio



Спасибо, понял, что надо сделать - в первые три варианта прописал p0<100 и все заработало.
#4 Objavljeno: 17. 8. 2021. 11:30:24
overlord

overlord

601 svidjanja u 1.382 postova.

Grupa: Moderator

Wrote

Спасибо, понял, что надо сделать - в первые три варианта прописал p0<100 и все заработало.


You don't have to describe p<100. Just re-order the if statements.
In original, third statement if condition gets true regardless of p.0 value.
When it gets the true value in if condition, it won't be looked for next if.
Moving the p.0 boolean check to first will make all conditions available to read.

You can use cases() for smaller, tidier and much readable if blocks.
Using nested if() and cases() will reduce the huge block of boolean.
Your φ.n - λ.n - h.q checks are same for all, nesting λ under it is possible.
And you can also use multiple boolean conditions. lele(),lelt(),gege(), etc.

Regards

proba_r1.sm (5,32 KiB) preuzeto 1247 put(ova).

2021-08-17_17-29.png
#5 Objavljeno: 18. 8. 2021. 10:56:50
Jean Giraud

Jean Giraud

983 svidjanja u 6.866 postova.

Grupa: User

Maths lele.sm (8,07 KiB) preuzeto 1286 put(ova).
#6 Objavljeno: 18. 8. 2021. 11:44:26
overlord

overlord

601 svidjanja u 1.382 postova.

Grupa: Moderator

You can even triple nest boolean checks.
0.5<=λ<=0.6 can be written as one cases().

Regards

2021-08-18_17-42.png
  • Novi postovi
  • Nema novih postova