2017-05-23 13 views
0
- (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"); 
    } 



} 

あなたのコードに「平易な言葉」のコメントを追加した場合に印刷されていないブロックが正しく私の要件に応じてnslogを印刷したいですか?

+0

ここではどのような問題がありますか? – KKRocks

+0

あなたの状態は間違っていますかチェックしてください(weightBMI <19){ NSLog(@ "low weight"); } else if((weightBMI> = 19)||(weightBMI <= 24) { NSLog(@ "low normal"); } else if((weightBMI <= 25)||(weightBMI <= 29)) { NSLog(@ "overweight"); } – iOS

答えて

0

それは多くの場合に役立ちます場合は、他に記述する方法について説明します。私はこれがあなたがテストしたいものだと仮定しています:

// 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"); 
} 
0

すぐにswiftを使用してコードを書いてください。短いです。 :)

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

     } 
関連する問題