Autor Beitrag
Nerdus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 19

WIN XP (Home)
Delphi 7
BeitragVerfasst: Do 14.06.07 18:55 
Hi Comm.,
vorab ich bin Anfänger und ich muss mit einem Kumpel in meiner Schule ein Programm schreiben, für die 3. und 4. Klässler.
Es soll dem Technick-und-Computer-Unterricht dienen! Ich bin für das Quiz dann verantwortlich...
Und da ergibt sich gleich meine Frage zu dem Quelltext:
Wie man sieht soll es mehrere Fragen geben, wo dann zufällig eine gezogen wird! Und dann dementsprechend bekommt man Punkte oder auch nicht :)
Wenn ich das Programm teste zählt er zweimal die drei Punkte dazu obwohl ich das gar nicht so deklariert hab. Ich bin mehrmals Schritt für SChritt durchgegangen aber zu keinem Ergebnis gekommen! :(
Mich macht das fertig.. ich kapier den Fehler nich (bzw. find)! wäre euch dankbar wenn jemand sich die Zeit nimm und den quelltext mal analysiert :) (P.S: x ist global deklariert)


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:
procedure fragen;
begin
x:=random(2)+1;
  if x=1 then
      begin
        Form1.Label1.Caption:=('Welche Lampe wird heller leuchten?');
        Form1.Label2.Caption:=('(3Punkte)');
        Form1.RadioGroup1.Items[0]:='Lampe 1';
        Form1.RadioGroup1.Items[1]:='Lampe 2';
        Form1.RadioGroup1.Items[2]:='keine leuchtet';
        Form1.RadioGroup1.Items[3]:='beide leuchten gleich';
      end;

if x=2 then
      begin
        Form1.Label1.Caption:='Was ist das für ein Element des Stromkreises?';
        Form1.Label2.Caption:='(3Punkte)';
        Form1.RadioGroup1.Items[0]:='Schalter';
        Form1.RadioGroup1.Items[1]:='Lampe';
        Form1.RadioGroup1.Items[2]:='Motor';
        Form1.RadioGroup1.Items[3]:='Klingel';
      end;
end;



procedure TForm1.FormCreate(Sender: TObject);
begin
randomize;
Label4.Caption:='0';
fragen;
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
var punkte : integer;
begin
punkte:=0;
if ((x=1) and (RadioGroup1.itemindex=0)) then
  begin
    punkte:=punkte+3;
    showmessage('Richtig! Du bekommst 3 Punkte!');
    Label4.Caption:=inttostr(punkte);
  end;
if ((x=1) and (RadioGroup1.itemindex<>0)) then
  begin
    showmessage('Falsch! Weiter zur nächsten Frage');
  end;


if ((x=2) and (RadioGroup1.itemindex=1)) then showmessage('Richtig! Du bekommst 3 Punkte!');
  begin
    showmessage('Richtig! Du bekommst 3 Punkte!');
    punkte:=punkte+3;
    Label4.Caption:=inttostr(punkte);
  end;
if ((x=2) and (RadioGroup1.itemindex<>1)) then
  begin
    showmessage('Falsch! Weiter zur nächsten Frage');
    Image5.Visible:=true;
  end;


Moderiert von user profile iconGausi: B- durch Delphi-Tags ersetzt
Jann1k
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 866
Erhaltene Danke: 43

Win 7
TurboDelphi, Visual Studio 2010
BeitragVerfasst: Do 14.06.07 20:06 
bei dir steht ein showmessage ausserhalb des begin-end, du hast es wohl versehentlich zweimal copy.pasted:

ausblenden 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:
procedure TForm1.BitBtn1Click(Sender: TObject);  
var punkte : integer;  
begin  
punkte:=0;  
if ((x=1) and (RadioGroup1.itemindex=0)) then  
  begin  
    punkte:=punkte+3;  
    showmessage('Richtig! Du bekommst 3 Punkte!');  
    Label4.Caption:=inttostr(punkte);  
  end;  
if ((x=1) and (RadioGroup1.itemindex<>0)) then  
  begin  
    showmessage('Falsch! Weiter zur nächsten Frage');  
  end;  

if ((x=2) and (RadioGroup1.itemindex=1)) then showmessage('Richtig! Du bekommst 3 Punkte!');//bitte entfernen
  begin  
    showmessage('Richtig! Du bekommst 3 Punkte!');  
    punkte:=punkte+3;  
    Label4.Caption:=inttostr(punkte);  
  end;  
if ((x=2) and (RadioGroup1.itemindex<>1)) then  
  begin  
    showmessage('Falsch! Weiter zur nächsten Frage');  
    Image5.Visible:=true;  
  end;
bflegel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 193
Erhaltene Danke: 1

Win XP, Win 7, BS2000
D5
BeitragVerfasst: Do 14.06.07 20:13 
Lass einfach in Zeile 50 das ShowMessage weg... das müsste es sein. Durch das Showmessage hebst Du die If-Abfrage auf und der folgende Code wird auf jeden Fall ausgeführt.

_________________
I know all the jokes about my name
Nerdus Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 19

WIN XP (Home)
Delphi 7
BeitragVerfasst: Fr 15.06.07 09:12 
Oh man bin ich blöd :D danke an euch^^
Ich hät noch ein Problem!^^
Und zwar ich will das ja Fragen zufällig gezogen werden, hab bis jetzt nur 2.. Aber wenn einmal die Frage gekommen ist solls sie ja nicht nochmal vorkommen. Und ich hab immer irgendwelche Lücken in meinen Veruschen das hinzubekommen!

Ich dachte mir so, dass in der Prozedur fragen Ein Feld von 1 bis 20 aufgefüllt wird sprich: Feld[1]=1, Feld[2]=2
Und dann soll er das mit x-wert vergleichen und wenn das nich so ist wieder die prozedur aufgerufen. aber da ist ein Hacken, da ja zwei anweisungen sind wenn z.b. x=2 ist: er vergleich x mit xwerte[i] und x mit 2... wenn xwerte[i] auch jetzt 2 ist hat er hat er zwei anweisungen! naja iwie brauch ich da auf jeden fall hilfe :D

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:
procedure fragen;
var xwerte : TFeld;
         i : integer;
begin
x:=random(2)+1;
for i:=1 to 20 do xwerte[i]:=i;
for i:=1 to 20 do
  begin
    if x=xwerte[i] then
      begin
        fragen
      end;
  end;

if x=1 then
      begin
        Form1.Image3.visible:=true;
        Form1.Label1.Caption:=('Welche Lampe wird heller leuchten?');
        Form1.Label2.Caption:=('(3Punkte)');
        Form1.RadioGroup1.Items[0]:='Lampe 1';
        Form1.RadioGroup1.Items[1]:='Lampe 2';
        Form1.RadioGroup1.Items[2]:='keine leuchtet';
        Form1.RadioGroup1.Items[3]:='beide leuchten gleich';
      end;

if x=2 then
      begin
        Form1.Image2.Visible:=true;
        Form1.Label1.Caption:='Was ist das für ein Element des Stromkreises?';
        Form1.Label2.Caption:='(3Punkte)';
        Form1.RadioGroup1.Items[0]:='Schalter';
        Form1.RadioGroup1.Items[1]:='Lampe';
        Form1.RadioGroup1.Items[2]:='Motor';
        Form1.RadioGroup1.Items[3]:='Klingel';
      end;
Wonko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 69



BeitragVerfasst: Fr 15.06.07 10:07 
Wenn ich Deine Frage richtig verstanden habe, suchst Du einen Weg, zu verhindern, dass eine Frage doppelt gestellt wird. Folgende Lösung schlage ich vor:
Nimm zwei Arrays: in das eine kommen die Fragen (oder halt die Verweise zu den entsprechenden cases); in dem zweiten (genauso langen) stehen zunächst nur Nullen und wenn die Frage gezogen wird, kommt an die Stelle eine Eins. Bei jedem Ziehen überprüfst Du, steht eine Eins oder eine Null im entsprechenden Eintrag: Null --> Frage stellen, Eins --> neue Frage ziehen.
Nerdus Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 19

WIN XP (Home)
Delphi 7
BeitragVerfasst: Sa 16.06.07 15:58 
Danke Wonko habs hinbekommen :)