请帮助修改一个简单小学生计算程序,目的想实现,当在EDIT里结果对话,label3:提示"对".不对的话提示"重新输入"(50)

楚辞

Unregistered / Unconfirmed
GUEST, unregistred user!
代码如下:label1,label3, edit1, button;var Form1: TForm1; int1,int2:integer;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject); begin if Trim(Edit1.Text) = '' thenbegin MessageBox(Handle, '请在文本框里输入结果', '系统提示', MB_ICONINFORMATION or MB_OK); Exit;end;begin tryif (StrToInt(edit1.Text)=(int1+int2)) thenbeginRandomize ;label1.Caption:=intTostr(int1)+'+'+intToStr(int2)+'=';end elsebeginlabel3.Caption:='输入正确,请计算下题';edit1.clear;end;exceptlabel3.Caption:='输入错误,请重新输入';edit1.clear;end;end; end;procedure TForm1.FormCreate(Sender: TObject);beginRandomize;int1:=random(10);int2:=random(10);label1.Caption:=intTostr(int1)+'+'+intToStr(int2)+'=';edit1.Text:='';end;
 
至少要好好排下版吧,看着太乱了。我排了一下版,大致改了一下,没有试,你试试看。var Form1: TForm1; int1, int2: integer;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);begin if Trim(Edit1.Text) = '' then begin MessageBox(Handle, '请在文本框里输入结果', '系统提示', MB_ICONINFORMATION or MB_OK); Exit; end; begin try if (StrToInt(edit1.Text)=(int1+int2)) then begin //Randomize ; //这句不要 int1:=random(10); //增加这句,重新生成int1 int2:=random(10); //增加这句,重新生成int2 label1.Caption:=intTostr(int1)+'+'+intToStr(int2)+'='; end else begin label3.Caption:='输入正确,请计算下题'; edit1.clear; end; except label3.Caption:='输入错误,请重新输入'; edit1.clear; end; end;end;procedure TForm1.FormCreate(Sender: TObject);begin Randomize; int1:=random(10); int2:=random(10); label1.Caption:=intTostr(int1)+'+'+intToStr(int2)+'='; edit1.Text:='';end;
 
unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Label1: TLabel; Label3: TLabel; Button1: TButton; Edit1: TEdit; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } int1, int2: integer; procedure NewIntegers; public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);begin if Trim(Edit1.Text) = '' then begin MessageBox(Handle, '请在文本框里输入结果', '系统提示', MB_ICONINFORMATION or MB_OK); Exit; end; begin try if (StrToInt(Edit1.Text) = (int1 + int2)) then begin NewIntegers; Label3.Caption := '输入正确,请计算下题'; Label1.Caption := intTostr(int1) + '+' + intTostr(int2) + '='; end else Label3.Caption := '输入错误,请重新输入'; Edit1.clear; Edit1.SetFocus; except Label3.Caption := '必须输入整数,请重新输入'; Edit1.SetFocus; end; end;end;procedure TForm1.FormCreate(Sender: TObject);begin Randomize; NewIntegers; Label1.Caption := intTostr(int1) + '+' + intTostr(int2) + '='; Edit1.Text := '';end;procedure TForm1.NewIntegers;begin int1 := random(10); int2 := random(10);end;end.
 
谢谢两位网友的相助.我想问下楼上的,procedure TForm1.NewIntegers;为什么写这个过程了?!
 
其实我的意思是想说,你怎么就能想到这层,我想不到....差距啊....
 
Label3.Caption := '必须输入整数,请重新输入';当我误输成小数时,点"确定"程序死掉了....并没有出现'必须输入整数,请重新输入';
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
593
import
I
顶部