Einzelnen Beitrag anzeigen

Tytomik

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

Rechner programmieren

  Alt 25. Feb 2011, 18:39
Hallo,
ich habe neu angefangen mit Delphi zu prgrammieren.
Und war heute dabei einen Rechner zu programmieren.(Mit Zufallszahlen).
Mit *,/,-,+ es funktionirte alles so weit ich habe es mit den Real zahlen gemacht.
Aber dann wollte ich noch einen neuen button machen, dass wenn man drauf drückt eine geteilt Aufgabe mit Rest ausgerechnet wird, allerdings ging das nur mit Integer und jetzt geht entweder nur das teilen mit Real Zahlen oder das teilen mit Rest also Integer. Meine Frage ist wo ist hier der Fehler :

Delphi-Quellcode:
unit Unit1;

interface

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

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

var a,b,c: Integer;
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
randomize;
a:= random(1001);
b:= random(1001);
Label1.Caption :=inttostr
(a);
Label2.Caption :=inttostr
(b);
form1.color:= clgreen;
Label3.Caption:= '0';


end;


procedure TForm1.Button2Click(Sender: TObject);
begin
Label3.caption:= inttostr(a+b);
If Strtoint(Label3.Caption)>500 then begin
Form1.Color:= clred;
end;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
Label3.caption:= inttostr(a-b);
If Strtoint(Label3.Caption)>500 then begin
Form1.Color:= clred;
end;

end;

procedure TForm1.Button4Click(Sender: TObject);
begin
Label3.caption:= inttostr(a*b);
If Strtoint(Label3.Caption)>500 then begin
Form1.Color:= clred;
end;
end;


procedure TForm1.Button6Click(Sender: TObject);
begin
Label3.caption:= inttostr(a div b);
Label4.caption:= inttostr(a mod b);
end;

procedure TForm1.Button5Click(Sender: TObject);
var a,b: real;
begin
Label3.caption:= floattostr(a-b);
If Strtofloat(Label3.Caption)>500 then begin
Form1.Color:= clred;

end;
end;
Freue mich bei positiver rückmeldung. Danke.

Geändert von MrSpock (25. Feb 2011 um 19:34 Uhr)
  Mit Zitat antworten Zitat