正如一个做法,我工作的一个应用程序,解决了著名中学勾股定理,一平方+ B平方= C的平方。不幸的是,出未来的谜底,在我眼里,没有任何实际的答案。这里是期间使用的代码中的“解决”动作。

- (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。有谁看到在程序的任何缺陷?由于事先!

有帮助吗?

解决方案

没仔细检查程序,但在第一线已经有一个很大的问题:

int lonesq = legoneint * legoneint;
int ltwosq = legtwoint * legtwoint;
int hyposq = hypotenuseint * hypotenuseint;

此瓦尔正在使用仍然没有在所有分配的VARS定义。您需要设置的乏从文本字段获取的值,然后做数学题。 C被顺序语言,一切都从上到下执行时,你不能说“A = B c”和一个会是B 下,在该程序的任何地方。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top