大家有知道的
就告诉一下哈
让大家好学习啊
这里不能用CASE语句,CASE语句只能是有序类型的变量
浮点型不是有序类型
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Edit1: TEdit;
Button1: TButton;
Label2: TLabel;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
//定义三个单精度浮点数,分别表示应纳税总额,区间应纳税总额,累加纳税额
var
sum, para, tax: single;
begin
//取得应纳税总额,并将累计纳税额变量置0
sum:=strtofloat(Edit1.Text); //这个函数进行从字符串到浮点型的转化
sum:=sum-800;
tax:=0;
//如果满足条件才执行相应代码
if sum>2000
then begin
para:=sum-2000; //计算位于2000~5000元之间的部分
sum:=sum-para; //从总额中减去一纳税额
tax:=tax+para*0.15; //累加求取纳税总额
end;
if sum>500
then begin
para:=sum-500;
sum:=sum-para;
tax:=tax+para*0.1;
end;
if sum>0
then tax:=tax+sum*0.05;
Edit2.Text:=floattostr(tax); //这个函数进行从浮点数到字符串的转化
end;
end.