我刚刚学习delphi,我想请教一下,如何做到当计算出两个数之间的和或差,另一个button按钮在按下时会弹出对与错的提示

解决方案 »

  1.   


    var
     a,b,c:integer;
    beigin
     a:=100;
     b:=200;
     c:=300;
     if (a+b=300) then 
       ShowMessage('正确')
      else
       ShowMessage('错误');
    end;
      

  2.   

    if (a+b = c) then
      ShowMessage('正确')
    else
       ShowMessage('错误');
      

  3.   

    果然是新人,蛋腾的问题,这个可以说是今年CSDN最easy问题了
      

  4.   

    搜 《Delphi5 开发人员指南》这书的pdf,有文字版的
      

  5.   

    不是a+b==c?
      

  6.   


    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Label1: TLabel;
        Label2: TLabel;
        Edit1: TEdit;
        Edit2: TEdit;
        Edit3: TEdit;
        Label3: TLabel;
        Label4: TLabel;
        Edit4: TEdit;
        Button1: TButton;
        procedure FormCreate(Sender: TObject);
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation
       uses Math,types;
    {$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var
      a,b,c,d:double;
    begin
      a := StrTointDef(Edit1.Text,0);     //数值1
      b := StrTointDef(Edit2.Text,0);     //数值2
      c := StrTointDef(Edit3.Text,0);     //两数之和
      d := StrTointDef(Edit4.Text,0);     //两数之差
      if (CompareValue(a+b,c) <> EqualsValue) then
      begin
        showMessage('两数之和不正确,正确值为' + floatTOStr(a+b));
        Exit;
      end;  if (CompareValue(a-b,d) <> EqualsValue) then
      begin
        showMessage('两数之差不正确,正确值为' + floatToStr(a-b));
        Exit;
      end;
      randomize;
      Edit1.Text := IntToStr(random(100));
      Edit2.Text := IntToStr(random(100));
      Edit3.Text := '';
      Edit4.Text := '';
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      Edit1.Text := '';
      Edit2.Text := '';
      Edit3.Text := '';
      Edit4.Text := '';
      randomize;
      Edit1.Text := IntToStr(random(100));
      Edit2.Text := IntToStr(random(100));
    end;end.