当前位置:编程学习 > Delphi >>

Delphi?代码?

procedure TForm1.Button1Click(Sender: TObject);
 var
 a,b,c,s,area:Single;
begin
  a:=strtofloat(edit1.Text);
  b:=strtofloat(edit2.Text);
  c:=strtofloat(edit3.Text);
  s:=(a+b+c)/2;
  if(s>0)And(s-a>0)And(s-b>0)And(s-c>0) Then
   begin
  area:=sqrt(s*(s-a)*(s-b)*(s-c));
  Label1.Caption:='能构成三角形的三边,该三角形的面积为:'+floattostr(area);
  end
  Else
   Label1.Caption:='不能构成三角形的三边。';
end;
  麻烦给看下这段代码是那里有错误就是不能运行(这是一个计算三角形面积的代码)
追问:

可是就是运行不了?不知道是那里有问题

 

答案:

你好,经测试上面代码没有问题,如图:

请问你那里是出现什么错误提示呢?

var
a,b,c:integer;
begin
    a:=Strtoint(edit1.Text);
    b:=Strtoint(edit2.Text);
    c:=Strtoint(edit3.Text);
    if (a+b<=c) or (b+c<=a) or (c+a<=b) then
        begin
            showmessage('不是三角形');
        end
    else
        begin
            showmessage('是三角形');
        end;
end;

能验证吗?

上一个:delphi 添加数据
下一个:delphi编程问题

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,