请帮用delphi 写一个最简洁的函数,来判断下面的数据!!!! 判断X,X=0~59 任何一个数 , 条件(X=0)返回值0 , (X大于0小于25)返回值0 ,
(X大于0 or X等于25, and X小于55  )返回值0.5,(X大于或等于55)返回值1。

解决方案 »

  1.   

    function F(X: Integer): Double;
    begin
      case X of
        0..24: Result := 0;
        25..54: Result := 0.5;
        55..59: Result := 1;
      else
        raise Exception.Create('数据超出范围');
      end;
    end;
      

  2.   

    如果區間相等, 就可以用除法解決.
    區間不相等,只能用if或case了.
      

  3.   

    如果X不是整数可以用下面的。
    function G(X: Double): Double;
    begin
      if X<0 then
        raise Exception.Create('数据超出范围')
      else if X<25 then
        Result:=0
      else if X<55 then
        Result:=0.5
      else if X<=59 then
        Result:=1
      else
        raise Exception.Create('数据超出范围');
    end;
      

  4.   

    function F(X: Integer): Double;
    begin
      if (x < 25)
        result := 0;
      else if (x>=25) and (x<55)
        result := 0.5;
      else if (x>=55) and (x<59)
        Result := 1;
      else
        raise Exception.Create('数据超出范围');
    end;
    这是if 的demo
      

  5.   

    function F(X: Integer): Double;
    begin
      Result:=int(x/5)/10;
    end;
      

  6.   

    也可能是
    function F(X: Integer): Double;
    begin
      Result:=(int(x/5))/10;
    end;