4
回答
计算器,输入的+号无法在switch(operator)中识别
终于搞明白,存储TCO原来是这样算的>>>   
- (IBAction)cal {
    NSString *number1 = self.num1.text;
    NSString *number2 = self.num2.text;
    NSString* operator = self.ope.text.;
    int n1 = number1.intValue;
    int n2 = [number2 intValue];
    float result;

    {
    switch(operator){
            case '+':
            result = n1 + n2;
            break;
            case '-':
            result = n1 - n2;
            NSLog(@"result:%d*********",result);
            break;
            case '*':
            result = n1 * n2;
            break;
            case '/':
            result = n1 / n2;
            break;
        }//switch
    } */
    self.result.text = [NSString stringWithFormat:@"%d",result];
    [self.view endEditing:YES];

}

源码下载:http://pan.baidu.com/s/1gdwIaBL

 想做一个只有+-*/功能的简单计算器,输入2个数,1个字符。但是输入的运算符好像不好。text输入的operator 是字符串类型,在switch(operator)中好像识别不出来。即使不用switch,用 if (operator == @"+");也不对。。

举报
慢跑20
发帖于2年前 4回/927阅
顶部