我正在編寫這本書「programming in objective c 2.0」,我不明白爲什麼這個程序不工作。基本上我需要建立一個程序來將華氏值轉換成一個攝氏值。超級簡單的程序不能正常工作
我打算只是簡單地解決它,沒有任何對象,只是使用直接的程序方法,任何方式我遇到的問題是,我定義的變量的值代表華氏或氏族值,的隨機。
這裏是我的代碼:
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
float fahrenheit;
float celciusConverted;
fahrenheit = 27.0;
celciusConverted = (fahrenheit - 32)/1.8 ;
NSLog(@"%f degrees fahrenheit is equal to %f degrees celcius") , fahrenheit, celciusConverted;
[pool drain];
return 0;
}
你是什麼意思的「種類隨機」?你每次都沒有得到相同的結果嗎?你能發表一些打印的日誌行嗎? – 2009-12-30 17:52:26