Thema: Delphi Fehler in Rechenprogramm

Einzelnen Beitrag anzeigen

kr1337

Registriert seit: 16. Nov 2013
6 Beiträge
 
#1

Fehler in Rechenprogramm

  Alt 16. Nov 2013, 12:21
Delphi-Version: 7
Hallo Leute,

ich habe mir eben gedacht mal ein kleines Rechenprogramm zu erstellen. Ich habe zunächst eine kleine Passwort-abfrage erstellt und dann zwei Radioboxen, in einer lässt sich einstellen welche Rechenart man rechnen möchte und in der 2. kann man den Zahlenbereich festlegen (100 oder 1000). Ich habe allerdings zwei Probleme zum einen hängt sich das Programm manchmal auf und zum andren, funktioniert das ganze für die Division nicht. Und zwar sollen dort vom Programm solange zwei Zufallszahlen n und m genereriert werden, bis das Ergebnis n/m ein integer Wert ist. Ich habe das ganze einfach so gemacht zunächst wird der Wert k per Zufall ausgewählt und dann wird n und m einfach so lange gebildet bis n/m k ergibt. Wenn ich das Programm dann jedoch starte und Division und den Zahlenbereich angeglickt habe und Button1 angegklickt habe kommt die Fehlermeldung :"Invalid floating point operation". Schonmal vielen Dank im Vorraus und hier ist der Quellcode:

Delphi-Quellcode:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Edit2: TEdit;
    RadioGroup1: TRadioGroup;
    RadioGroup2: TRadioGroup;
    Label13: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1; passworttrue: boolean; passwort, eingabe: string; n, m, k : integer;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
passwort := '123456';
eingabe:= edit1.Text;
passworttrue := (passwort=eingabe);
if passworttrue then
begin
  label1.Visible:= true;
  label2.Visible:= true;
  label3.Visible:= true;
  edit2.Visible:= true;
end;
randomize;
k := random(1000)+1;
case RadioGroup1.ItemIndex of
  0: begin
      label2.caption:= '+';
      REPEAT
        if radiogroup2.ItemIndex=0 then
        begin
        n := random(100) +1; m:= random(100) +1;
        end;
      UNTIL m+n <=100;
      REPEAT
        if radiogroup2.ItemIndex=1 then
        begin
        n := random(1000)+1; m:= random(1000) +1;
        end;
      UNTIL m+n <=1000;
      label1.Caption := floattostr(n);
      label3.Caption := floattostr(m);
      end;
  1: begin
      label2.caption:= '-';
      REPEAT
        if radiogroup2.ItemIndex=0 then
        begin
        n := random(100) +1; m:= random(100) +1;
        end;
      UNTIL n>m;
      REPEAT
        if radiogroup2.ItemIndex=1 then
        begin
        n := random(1000)+1; m:= random(1000) +1;
        end;
      UNTIL n>m;
      label1.Caption := floattostr(n);
      label3.Caption := floattostr(m);
      end;
  2: begin
      label2.caption:= 'x';
      REPEAT
        if radiogroup2.ItemIndex=0 then
        begin
        n := random(100) +1; m:= random(100) +1;
        end;
      UNTIL n*m <=100;
      REPEAT
        if radiogroup2.ItemIndex=1 then
        begin
        n := random(1000)+1; m:= random(1000) +1;
        end;
      UNTIL n*m <= 1000;
      label1.Caption := floattostr(n);
      label3.Caption := floattostr(m);
      end;
  3: begin
      label2.caption:= ':';
      REPEAT
        if radiogroup2.ItemIndex=0 then
        begin
        n := random(100) +1; m:= random(100) +1;
        end;
      UNTIL (n>=m) and (n/m = k);
      REPEAT
        if radiogroup2.ItemIndex=1 then
        begin
        n := random(1000)+1; m:= random(1000) +1;
        end;
      UNTIL (n>=m) and (n/m = k);
      label1.Caption := floattostr(n);
      label3.Caption := floattostr(m);
      end;
end;
end;

end.
  Mit Zitat antworten Zitat