2014-09-01 57 views
0

我也寫了一個聲明的Objective-C,C多的平等跡象之一,如果

if (sample.value > shortAverage > shortWithoutFirstAverage > longAverage) { 

和預期sample.value> longAverage

但是,這並不工作,它可能發生的樣品。值< longAverage

(lldb) p (sample.value > shortAverage > shortWithoutFirstAverage > longAverage) 
(bool) $13 = true 
(lldb) p sample.value 
(double) $14 = 0.029 
(lldb) p longAverage 
(double) $15 = 0.032 
(lldb) p (sample.value > longAverage) 
(bool) $16 = false 
(lldb) p shortAverage 

其它值

(double) $17 = 0.029821 
(lldb) p shortWithoutFirstAverage 
(double) $18 = 0.029802 

它看起來是作爲

評估,如果((sample.value> shortAverage)>(shortWithoutFirstAverage> longAverage)){

但如何實現if語句?所需,使其true(sample.value> shortAverage> shortWithoutFirstAverage> longAverage)

回答

1

你不能像檢查這 -

表達
if (sample.value > shortAverage > shortWithoutFirstAverage > longAverage) 

使用 -

if ((shortWithoutFirstAverage > longAverage) && (shortAverage > shortWithoutFirstAverage) && (sample.value > shortAverage)) 
1

您不能在C語言和相關語言中鏈接這樣的二進制運算符,如>

變化:

if (sample.value > shortAverage > shortWithoutFirstAverage > longAverage) { 

到:

if (sample.value > shortAverage && 
    shortAverage > shortWithoutFirstAverage && 
    shortWithoutFirstAverage > longAverage) { 
1

只要做到這一點這樣:

if ((sample.value > shortAverage) && (shortAverage > shortWithoutFirstAverage) && (shortWithoutFirstAverage > longAverage))