2017-05-23 10 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 (@ "저체중"); } else if ((weightBMI> = 19) || (weightBMI <= 24) { NSLog (@ "low normal"); } else if ((weightBMI <= 25) || (weightBMI <= 29) { NSLog (@ "over weight"); } – 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") 

     } 
관련 문제