Autor Beitrag
Hannah1990
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: Do 09.11.06 16:57 
Hi,

zuerst Mal : Ja, ich hab mir die anderen Zahlen-Raten-Threads durchgelesen, komm aber nich weiter....

Das Programm funktioniert nicht so, wie es soll..... Hier mal der Programm-Text

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
unit Unit1;
  
interface

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

type
  TForm1 = class(TForm)
    btnRetry: TButton;
    btnOK: TButton;
    Button3: TButton;
    Panel1: TPanel;
    Panel2: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    Edit1: TEdit;
    procedure Button3Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure btnRetryClick(Sender: TObject);
    procedure btnOKClick(Sender: TObject);

  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  zufallszahl :integer ;
  Eingabe :integer ;

implementation

{$R *.DFM}











procedure TForm1.Button3Click(Sender: TObject);
begin
close
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Randomize;
Zufallszahl := (100) +1
end;

procedure TForm1.btnRetryClick(Sender: TObject);
begin
Randomize;
Zufallszahl := (100) +1
end;

procedure TForm1.btnOKClick(Sender: TObject);

 begin
  if Eingabe=Zufallszahl
     then Panel2.Caption := 'Das war richtig!'
     else if Eingabe<Zufallszahl
          then Panel2.Caption := 'Die Zahl ist zu klein!'
          else if Eingabe>Zufallszahl
               then panel2.Caption:= 'Die Zahl ist zu groß!'
               else if  Eingabe<0
                    then panel2.caption := 'Die Zahl muss größer als 0 sein! '
                    else if Eingabe>100
                    then panel2.caption := 'Die Zahl muss kleiner als 100 sein!'

                    end;










end.




Egal, welche Zahl ich eingebe, es kommt immer :"Die Zahl ist zu klein !"


Wär klasse,wenn mir jemand helfen könnte :)
azubi_20
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 593

WinXP SP2, Ubuntu 8.4
D7 Enterp., D2005 Prof., Java (Eclipse 3.4.0)
BeitragVerfasst: Do 09.11.06 17:03 
Dein "Zufallszahl" ist immer 101. Les dir mal die Beschreibung zur Funktion random() durch.
DaKirsche
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 187

Win XP Pro, SuSe Linux 7.3 - 10.2, Win 2k3 Server, Win 2000, Win NT 4.0
Delphi 2006 Pro, Java, HTML, SQL, PHP, CSS
BeitragVerfasst: Do 09.11.06 17:05 
Das liegt daran, dass du keine Zufallszahl generierst:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure TForm1.FormCreate(Sender: TObject);  
begin  
Randomize;  
Zufallszahl := (100) +1  
end;  

 
procedure TForm1.btnRetryClick(Sender: TObject);  
begin  
Randomize;  
Zufallszahl := (100) +1  
end;


Nur Randomize; bringt dir wenig....

Deine Zufallszahl ist immer Zufallszahl:=(100)+1 -->ergibt 101 ! IMMER!

Du musst folgendes machen:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm1.FormCreate(Sender: TObject);  
begin  
Randomize;
btnRetryClick(Sender);
end;  

 
procedure TForm1.btnRetryClick(Sender: TObject);  
begin  
Zufallszahl := random(100) +1  
end;



//Edit: Och mann...zu langsam:(
Hannah1990 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: Do 09.11.06 18:00 
Danke :)
Hannah1990 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: Do 09.11.06 20:19 
Hmmm...irgendwie klappts jetzt trotzdem noch ncih :(

Mein text :


ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
  unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Panel2: TPanel;
    Label1: TLabel;
    Edit1: TEdit;
    btnRetry: TButton;
    btnOK: TButton;
    btnclose: TButton;
    procedure btncloseClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure btnRetryClick(Sender: TObject);
    procedure btnOKClick(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  zufallszahl :integer ;
  Eingabe :integer ;

implementation

{$R *.DFM}

procedure TForm1.btncloseClick(Sender: TObject);
begin
close
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Randomize;
Zufallszahl := random(100) +1
end;

procedure TForm1.btnRetryClick(Sender: TObject);
begin
Randomize;
Zufallszahl := random (100) + 1
end;

procedure TForm1.btnOKClick(Sender: TObject);
begin
  if Eingabe=Zufallszahl
     then Panel2.Caption := 'Das war richtig!'
     else if Eingabe<Zufallszahl
          then Panel2.Caption := 'Die Zahl ist zu klein!'
          else if Eingabe>Zufallszahl
               then panel2.Caption:= 'Die Zahl ist zu groß!'
               else if  Eingabe<0
                    then panel2.caption := 'Die Zahl muss größer als 0 sein! '
                    else if Eingabe>100
                    then panel2.caption := 'Die Zahl muss kleiner als 100 sein!'
end;

end.



wahh, ich bin zu blöd für Informatik
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Do 09.11.06 20:46 
Hey Hannah,
es reicht, wenn du randomize im FormCreate aufrufst!
Außerdem gewöhn dir bitte an, richtig einzurücken und if then auf eine Linie zu schreiben:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
begin
  if Eingabe = Zufallszahl then
    Panel2.Caption := 'Das war richtig!'
  else
    if Eingabe < Zufallszahl then
      Panel2.Caption := 'Die Zahl ist zu klein!'
    else
      if Eingabe > Zufallszahl then
        panel2.Caption := 'Die Zahl ist zu groß!'
      else
        if Eingabe < 0 then
          panel2.caption := 'Die Zahl muss größer als 0 sein! '
        else
          if Eingabe > 100 then
            panel2.caption := 'Die Zahl muss kleiner als 100 sein!'
end;


grüße marc
Hannah1990 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: Do 09.11.06 20:49 
Ah,okay, danke, ich probiers ma
BerTeL
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 45

Windowx XP
Delphi 7 Enterprise
BeitragVerfasst: Do 09.11.06 20:49 
ich bin zwar selber noch nicht so gut aber irgendwas fehlt da ...

du hast eingabe dekliniert ... aber ihr nie einen wert gegeben oO (oder hab ich da was verpasst).
Beim buttonclick müsste etwas wie
eingabe := strtoint(edit1.text);
Denn es ist ja nichts da zum vergleichen >.<
außerdem würde es genügen die variable local zu machen (bei der procedure btnOKclick) denn sie wird sonst nie gebraucht ...
Was ich noch nicht verstehe ist das +1 ... wenn random zufällig 100 gibt kommt dan 101 heraus >.< und da mann ja nicht über 100 darf ist es nicht möglich ...

Für fehler sag ich nochmal: bin selber noch fortgeschrittener anfänger
rizla
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 417
Erhaltene Danke: 2

XP
FPC mit Lazarus
BeitragVerfasst: Do 09.11.06 20:55 
Mist bertel war schneller, allerdingens:
random(100)+1 ist richtig damit zahlen größer als 0 rauskommen und
im btnOKclick noch
ausblenden Quelltext
1:
Eingabe := strtoint(edit1.text)					


so jehts

:r!a:

_________________
if you have what they want - they'll find a way to take it (bruce sterling)
WOW - 10 JAHRE Mitglied beim Delphi-Forum. Wie die Zeit vergeht, Freunde.


Zuletzt bearbeitet von rizla am Do 09.11.06 20:56, insgesamt 1-mal bearbeitet
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Do 09.11.06 20:56 
Zitat:
Deine Zufallszahl ist immer Zufallszahl:=(100)+1 -->ergibt 101 ! IMMER!

Das ist übrigens völliger Stuss! Da bei random(100) zufallszahlen zwischen 0 und 99 rauskommen! ;) Du rechnest +1 um Zahlen zwischen 1 und 100 zu erhalten!
jakobwenzel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1889
Erhaltene Danke: 1

XP home, ubuntu
BDS 2006 Prof
BeitragVerfasst: Do 09.11.06 21:09 
Da stand aber nicht random(100)+1 sondern (100)+1. Und da kommt wirklich immer 101 raus. :roll:

_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.
DaKirsche
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 187

Win XP Pro, SuSe Linux 7.3 - 10.2, Win 2k3 Server, Win 2000, Win NT 4.0
Delphi 2006 Pro, Java, HTML, SQL, PHP, CSS
BeitragVerfasst: Do 09.11.06 21:24 
das ist so schon korrekt...random(100) nimm eine Zufallszahl aus den 1. 100 Zahlen...incl. 0.
Also grob umschrieben eine zahl aus dem array [0..99]

und deshalb +1.

Und Zufallszahl:=(100)+1 ... da steht nix von random!
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Do 09.11.06 21:44 
ja, ich hab mich verlesen. Eigentlich galt die Antwort auch für user profile iconBertel! ;)

grüße marc