Einzelnen Beitrag anzeigen

Tytomik

Registriert seit: 25. Feb 2011
24 Beiträge
 
#1

Taschenrechner

  Alt 28. Feb 2011, 13:31
Hallo,
ich habe heute einen taschenrechner prgrammiert.
Mit 2 Eingabefelder und 4 Button mit +,-,*,/ und einem label.
Es funktioniert auch alles aber ich will jetzt noch einen 5. Button machen das wenn man auf den klickt zfällig ist ob +,-,* oder / kommt.

Hier noch mal der queltext:
(Quelltext)
Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Label1: TLabel;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var a,b,c:Real;
begin
randomize;
Form1.Color:=random(255*255*255);
a:=strtofloat(Edit1.Text);
b:=strtofloat(Edit2.Text);
c:=a+b;
Label1.caption:=floattostr(c);
If c=10 then begin
Form1.Color:=clred;

end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var a,b,c:Real;
begin
randomize;
Form1.Color:=random(255*255*255);
a:=strtofloat(Edit1.Text);
b:=strtofloat(Edit2.Text);
c:=a-b;
Label1.caption:=floattostr(c);
If c=10 then begin
Form1.Color:=clgreen;
end;
end;

procedure TForm1.Button3Click(Sender: TObject);
var a,b,c:Real;
begin
randomize;
Form1.Color:=random(255*255*255);
a:=strtofloat(Edit1.Text);
b:=strtofloat(Edit2.Text);
c:=a*b;
Label1.caption:=floattostr(c);
If c=25 then begin
Form1.Color:=clyellow;

end;
end;

procedure TForm1.Button4Click(Sender: TObject);
var a,b,c:Real;
begin
randomize;
Form1.Color:=random(255*255*255);
a:=strtofloat(Edit1.Text);
b:=strtofloat(Edit2.Text);
c:=a/b;
Label1.caption:=floattostr(c);
If c=5 then begin
Form1.Color:=clblue;

end;
end;



end.

Freue mich auf rückmeldung.

Geändert von Sharky (28. Feb 2011 um 14:04 Uhr)
  Mit Zitat antworten Zitat