我想知道如何在textfield中使用括号实现单行计算。
我想获取文本字符串输入并相应地解析它以获取正确的值并将其发送给以下代码或任何其他建议的方法
#import "calculate.h"
@implementation calculate
+(double)arithmetic:(double)firstNumber enterCharacter:(int)characterType enterSecond:(double)secondNumber
{
double result;
switch (characterType)
{
case 0:
result= firstNumber+secondNumber;
break;
case 1:
result= firstNumber-secondNumber;
break;
case 2:
result= firstNumber/secondNumber;
break;
case 3:
result= firstNumber*secondNumber;
break;
case 4:
result= pow(firstNumber,secondNumber);
break;
default:
return 0;
break;
}
return result;
}
@end