比如购买金额为100,卖家获利90元,介绍人获利10元,如果交易金额为100元以上,比如325元,那么卖家获利300元,介绍人获利25元(10+5+5+5),也就是超过100元,每100介绍费为5元,基础介绍费为10元,怎么写这个函数?参数应为交易金额。

解决方案 »

  1.   

    function GetAmount(AAmount: Currency): Currency;
    begin
      if AAmount < 100 then
      begin
        Result := 10;
        Exit;
      end;
      Result := 10 + Amount div 100 * 5;
    end;
      

  2.   

    procedure GetPrice(input:integer;var iSellPrice,iIntrPrice:integer);
    var
        i:integer;
        All:integer;
    begin
        All:=input;
        iIntrPrice:=10;
        while All>100 do
        begin
            inc(iIntrPrice,5);
            inc(All,-100);
        end;
        iSellPrice:=input-iIntrPrice;
    end;procedure TForm1.Button1Click(Sender: TObject);
    var
        i1,i2:integer;
    begin
        GetPrice(StrToInt(Edit1.Text),i1,i2);
        Label1.Caption:=IntToStr(i1);
        Label2.Caption:=IntToStr(i2);
    end;