AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Fehler in Rechenprogramm

Ein Thema von kr1337 · begonnen am 16. Nov 2013 · letzter Beitrag vom 16. Nov 2013
 
kr1337

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

Fehler in Rechenprogramm

  Alt 16. Nov 2013, 13: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
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 22:02 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz