Einzelnen Beitrag anzeigen

Tytomik

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

Taschenrechner mit Rest (6/5= 1 rest 1)

  Alt 2. Mär 2011, 17:10
hallo,
ich bin grad dabei einen taschenrechner zu programmieren.
Will einen der auch bin rest rechnet da ich aber / habe muss ich real zahlen nehemn und keine integer zahlen ( also kein div und mod). Und dann habe ich gelesen das man das mir round ab und aufrunden kann aber wo ist hier der fehler ( button6).



Delphi-Quellcode:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Label1: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    Button5: TButton;
    Label2: TLabel;
    Button6: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  a,b,c,d: Real;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
a:= strtofloat(Edit1.Text);
b:= strtofloat(Edit2.Text);
c:= a+b;
Label1.Caption:=floattostr(c);
Form1.color:=random(255*255*255);

end;

procedure TForm1.Button2Click(Sender: TObject);
begin
a:= strtofloat(Edit1.Text);
b:= strtofloat(Edit2.Text);
c:= a-b;
Label1.Caption:=floattostr(c);
Form1.color:=random(255*255*255);
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
a:= strtofloat(Edit1.Text);
b:= strtofloat(Edit2.Text);
c:= a*b;
Label1.Caption:=floattostr(c);
Form1.color:=random(255*255*255);
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
a:= strtofloat(Edit1.Text);
b:= strtofloat(Edit2.Text);
If b=0
then begin showmessage('Division durch 0 nicht möglisch');
c:= a/b;
Label1.Caption:=floattostr(c);
Form1.color:=random(255*255*255);
end;
end;

procedure TForm1.Button5Click(Sender: TObject);
var d: Integer;
begin
randomize;
d:=random(4);
case d of
0: Button5.Click;
1: Button2.Click;
2: Button3.Click;
3: Button4.Click;


end;
end;
procedure TForm1.Button6Click(Sender: TObject);
begin
a:=round(strtofloat);//hier wird der Fehler angezeigt
b:=round(strtofloat);
c:=a div b;
Label1.caption:=floattostr(c);
d:=a mod b;
Label2.Caption:=floattostr(d);
end;
end.

Danke
  Mit Zitat antworten Zitat