2013-12-21 59 views
-2

我有這樣的代碼:簡單的iOS數學

- (IBAction)submitButton:(id)sender { 
     int a = 1 + arc4random() % 9; 
     int b = 1 + arc4random() % 9; 
     self.question.text = [NSString stringWithFormat:@"%d + %d", a + b]; 
} 

我想建立一個數學問題的應用程序,並與

self.question.text = [NSString [email protected]"%d + %d", a + b]; 

行它給了我,說

More '%' conversions than data arguments 
錯誤

我該如何解決這個問題?

回答

0

必須:

self.question.text = [NSString [email protected]"%d + %d=%d",a, b, a + b]; 

爲你的情況另一種選擇是:

self.question.text = [NSString [email protected]"%d + %d",a, b]; 

你有一個說法,當您需要兩個或三個。 希望這有助於。

+0

是的,我發現後,我發佈!哎呀!謝謝你,雖然 – MicahKE

+0

很酷,請接受答案,如果有人有類似的問題。 – Foriger