ちょうど練習として、有名な中学生のピタゴラスの定理、a の 2 乗 + b の 2 乗 = c の 2 乗を解くアプリに取り組んでいます。残念ながら、私の目には、出てくる答えは実際の答えとは何の関係もありません。「解決」アクション中に使用されるコードは次のとおりです。
- (IBAction)solve {
int legoneint;
int legtwoint;
int hypotenuseint;
int lonesq = legoneint * legoneint;
int ltwosq = legtwoint * legtwoint;
int hyposq = hypotenuseint * hypotenuseint;
hyposq = lonesq + ltwosq;
if ([legone.text isEqual:@""]) {
legtwoint = [legtwo.text intValue];
hypotenuseint = [hypotenuse.text intValue];
answer.text = [NSString stringWithFormat:@"%d", legoneint];
self.view.backgroundColor = [UIColor blackColor];
}
if ([legtwo.text isEqual:@""]) {
legoneint = [legone.text intValue];
hypotenuseint = [hypotenuse.text intValue];
answer.text = [NSString stringWithFormat:@"%d", legtwoint];
self.view.backgroundColor = [UIColor blackColor];
}
if ([hypotenuse.text isEqual:@""]) {
legoneint = [legone.text intValue];
legtwoint = [legtwo.text intValue];
answer.text = [NSString stringWithFormat:@"%d", hypotenuseint];
self.view.backgroundColor = [UIColor blackColor];
}
}
ちなみに、すべて直角三角形の各数学的部分に対応する を legone, legtwo, and hypotenuse
表しています。ご想像のとおり、それが答えです。プログラムに欠陥がある人はいますか? 前もって感謝します!UITextField
Answer
UILabel