仍在学习目标c并出现问题我只是无法弄清楚。我正在尝试编写一个应用程序来绘制角度,我有4个文本区域,2个边和2个角度。用户可以输入2个侧面的尺寸,应用程序会计算出角度,或者用户可以输入1侧和角度,应用程序会计算出另一侧和角度。在此我搞清楚如何得到这个工作我做了这个代码的过程:需要Objective-C程序的建议
- (IBAction)calcPressed {
float a = ([sideA.text floatValue]/[sideB.text floatValue]);
float b = atan(a)*180/3.141592653589;
float e = 90 - b;
angleA.text = [[NSString alloc] initWithFormat:@"%f", b];
angleB.text = [[NSString alloc] initWithFormat:@"%f", e];
采取两面进入,并计算角度和正常工作。所以现在我需要弄清楚如何允许输入或者两面或1个侧,1角,所以我想出了这一点:
- (IBAction)calcPressed {
float a = ([sideA.text floatValue]);
float b = ([sideB.text floatValue]);
float c = ([angleA.text floatValue]);
float d = ([angleB.text floatValue]);
if(angleA.text, angleB.text = @"") {
float e = a/b;
float f = atan(e)*180/3.141592653589;
float g = 90 - f;
angleA.text = [[NSString alloc] initWithFormat:@"%f", f];
angleB.text = [[NSString alloc] initWithFormat:@"%f", g];
} else if (sideB.text, angleB.text = @"") {
float e = tan(c);
b = a/e;
d = 90 - c;
sideB.text = [[NSString alloc] initWithFormat:@"%f", b];
angleB.text = [[NSString alloc] initWithFormat:@"%f", d];
}
}
第一部分工作正常,但第二部分不。就像我说过的,我对此很新颖,我相信有更好的做法,比如可能有更好的方法来分割pi,但是我可以开始工作。任何指针将不胜感激。
你觉得表达式'if(angleA.text,angleB.text = @“”)'是做什么的? – Jonah
在分割之前,您应该检查数字是否为0。 – dasdom