2014-04-17 11 views
0

我在目標C中創建了一個數組並填充了一些數字(我認爲),並且我想知道如何引用其中的一個數字數組來完成一個非常基本的數學問題,但我不確定如何去做這件事。引用數組中的整數來完成目標中的數學運算C

下面是我創建數組:

NSMutableArray *combo = [NSArray arrayWithObjects: [NSNumber numberWithInt:24], [NSNumber numberWithInt:5], [NSNumber numberWithInt:27], nil]; 

這是一道數學題,我嘗試使用數組來創建:

abs(-1440 - 7.2*[combo objectAtIndex:0])*.01 

謝謝大家的幫助提前!請讓我知道,如果你覺得我的問題不夠清楚

+1

在'NSNumber's值必須通過調用它的[多存取]的一個(https://developer.apple.com/library/mac/documentation/cocoa提取/reference/foundation/classes/nsnumber_class/Reference/Reference.html),然後才能像int那樣對待它。 – CodaFi

回答

0

如評論所述,你需要訪問數組中的NSNumber對象的數值。所以,你要做到這一點:

abs(-1440 - 7.2*[[combo objectAtIndex:0] intValue])*.01