【问题标题】:in switch case i want to print nslog as per my requirement?在开关情况下,我想根据我的要求打印 nslog?
【发布时间】:2017-10-23 12:21:48
【问题描述】:
- (IBAction)calciAction:(id)sender {

        weightBMI=(([_weightinpounds.text floatValue]) * 4.88)/((([_feet.text floatValue])+ ([_inch.text floatValue]/12)) *(([_feet.text floatValue])+ ([_inch.text floatValue]/12)));

    NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
    formatter.numberStyle = NSNumberFormatterDecimalStyle;
    formatter.maximumFractionDigits = 2;
    formatter.roundingMode = NSNumberFormatterRoundUp;

    NSString *numberString = [formatter stringFromNumber:@(weightBMI)];
    NSLog(@"YOUR BMI:%@",numberString);

   // NSLog(@"Print BMI %f",weightBMI);
   // float height = (([_feet.text floatValue]) + ([_inch.text floatValue]));


    if (weightBMI>19) {
        NSLog(@"low weight");
    }
    else if ((weightBMI<=19)||(weightBMI>=24))
    {
        NSLog(@"low normal");
    }
    else if ((weightBMI<=25)||(weightBMI>=29))
    {
        NSLog(@"over weight");
    }



}

如果没有正确打印的块如何写入else

【问题讨论】:

  • 这里面临什么问题?
  • 你的情况是错误的 检查这个 if (weightBMI=19)||(weightBMI

标签: ios ios5 ios4 ios-3.x ios3.0


【解决方案1】:

在代码中添加“普通语言”cmets 通常会有所帮助。我假设这是您要测试的内容:

// if weightBMI is LESS THAN 19, weight is low
// if weightBMI is GREATER THAN or EQUAL TO 19, but LESS THAN 25, weight is normal
// if weightBMI is EQUAL TO or GREATER THAN 25, weight is over

if (weightBMI < 19) 
{
    NSLog(@"low weight");
}
else if (weightBMI < 25)
{
    NSLog(@"normal");
}
else
{
    NSLog(@"over weight");
}

【讨论】:

    【解决方案2】:

    如果您将来使用 swift 编写代码。因为它很短。 :)

     switch weightBMI {
            case Int.min..<20:
                print("low weight")
            case 20..<26:
                print("low normal")
            default:
                print("over weight")
    
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-01
      • 1970-01-01
      • 2016-07-29
      • 1970-01-01
      • 2017-11-13
      • 1970-01-01
      相关资源
      最近更新 更多