1

Objective CI で順列と組み合わせを取得したいのですが、両方が見つかりましたが、コードに問題があり、どこで発生しているのかわかりません。実際にはテキストフィールドに値を出力したいのですが、最後に入力した値が出力されます。以下のコードを使用しました。誰か助けてください..

    typedef enum{Power,Exponent,nCr,nPr} CalcOperation;
    NSString *storage;
    CalcOperation operation;
   -(IBAction)combination{ 
    operation = nPr; 
    storage = label.text;
    textField.text=@"";
    label.text = @"";
    }

   -(int) factorial:(int)n{
   int d = n;
   int temp = 1;
   for(int b = 2; b <= d; b++){
    temp = temp*b;
   }
  //NSLog(@"the factorials is = %i",temp);

  return temp;
 }

 -(IBAction)equalButton{
  float tempo = [storage floatValue];
  float b = [label.text floatValue];
  NSString *val = [[NSString alloc]initWithFormat:@"%f" , b];  

    switch(operation) {
     case nCr:

     textField.text = [[NSString alloc]initWithFormat:@"%f",[self factorial:tempo] / ([self factorial:[val floatValue]] * [self factorial:tempo-[val floatValue]])]; 
            //textField.text = [[NSString alloc]initWithFormat:@"%f",[val floatValue]+tempo+10];
          NSLog(@"combination %d",[self factorial:tempo] / ([self factorial:[val floatValue]] * [self factorial:tempo-[val floatValue]]));
            break;
    case nPr:

            textField.text = [[NSString alloc]initWithFormat:@"%f",[self factorial:tempo] / [self factorial:tempo-[val floatValue]]]; 
           NSLog(@"permutations %d",[self factorial:tempo] / ([self factorial:tempo-[val floatValue]]));
            break;  `
                  }
                }
4

1 に答える 1