Autor Beitrag
Greek
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 45



BeitragVerfasst: Mi 29.10.08 15:07 
Hallo!!
Hab ne Hausaufgabe auf und grig sie noch net so ganz hin:
Gesucht ist ein Programm zur Einübung des Einmaleins von 2 mal 2 bis 12 mal 12. Hierzu Werden zehnmal zufällige Multiplikationensaufgaben erzeugt und am Bildschirm angezeigt. Wird vom Benutzer das falsche Ergebnis eingegeben, soll der Hinweis 'falsch' und das richtige Ergebnis ausgegeben werden.

Die fehlerhaften Ergebnisse werden gezählt. Beträgt die Fehlerzahl mehr als 5, dann wird das gesamte Programm wiederholt, d.h. es werden zehn neue Aufgaben zufällig ausgewählt, ingesamt höchstens aber dreimal.
Würde das Programm nur einmal durchlaufen sollen zum Abschluss die Meldungen:

weniger als 2 Fehler: sehr gut
weniger als 4 Fehler: gut
sonst : schwach
ausgegeben werden, ansonsten der Hinweis: Morgen noch einmal üben!

so das ist die Aufgabe.

Das hab ich bis jetzt, aber ich grig das einfach nicht hin :( :
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
var rzahl1, rzahl2, j : integer;
begin
  j:=StrToInt(Edit4.Text);
  rzahl1:=Random( 12 )+2;
  rzahl2:=Random( 12 )+2;
  Edit1.Text:=IntToStr(rzahl1);
  Edit2.Text:=IntToStr(rzahl2);
  j:=j+1;
  Edit4.Text:=IntToStr(j);


Moderiert von user profile iconGausi: Code- durch Delphi-Tags ersetzt
Mike19
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 256

Win XP, Vista, Win 7
Delphi 2005, Turbo Delphi
BeitragVerfasst: Mi 29.10.08 15:17 
Hallo,

Zitat:
Hierzu Werden zehnmal zufällige Multiplikationensaufgaben erzeugt und am Bildschirm angezeigt


hast Du Dir mal Gedanken gemacht, wie Du die 10 Aufgaben erstellen willst, versuchs mal einer Schleife (for oder while). Dann fällt Dir dann auch der Rest ein. Wenn Du noch weitere Fragen dazu hast, stell sie hier.

Gruss

Michael
Greek Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 45



BeitragVerfasst: Mi 29.10.08 15:22 
Ich wollte machen, das man den Button drückt, die nächste aufgabe da steht...

und dann ist da noch nen Input feld, wo die runde drin steht, das ließt er dann aus und weis in welcher runde er ist, aber jetzt hab ich ein problem: er soll j:j+1 machen, aber das macht er nur bis 9! danach geht er wieder auf 1 und bleibt dann da.. wieso?
Mike19
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 256

Win XP, Vista, Win 7
Delphi 2005, Turbo Delphi
BeitragVerfasst: Mi 29.10.08 15:32 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
var rzahl1, rzahl2, j : integer;


begin
  
  j:=StrToInt(Edit4.Text); 
  rzahl1:=Random( 12 )+2;
  rzahl2:=Random( 12 )+2;
  Edit1.Text:=IntToStr(rzahl1);
  Edit2.Text:=IntToStr(rzahl2);
  j:=j+1;
  Edit4.Text:=IntToStr(j);


kann hier nicht erkennen, ob es globale Variablen oder lokale sind. Ist j eine globale Variable wäre es Sinvoll mit

for j:=1 to 10 zu arbeiten.

Noch ein Tip, ich würde Ausgabefelder nicht als Editfelder nehmen, sondern Labels.

Michael
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mi 29.10.08 15:42 
Eine for-Schleife bringt hier meiner Meinung nach erstmal gar nichts. Das wäre der richtige Ansatz in einer Konsolen-Anwendung, aber nicht in einer Event-basierten Fensteranwendung.

Mal ein paar Gedanken dazu. Ich würde (ich weiß, globale Variablen sind böse, meinetwegen nimmt man dann halt ne Property der Form) ein paar globale Variablen anlegen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
var
  Rundenzahl: Integer;
  AktuellerFaktor1: Integer;
  AktuellerFaktor2: Integer;
  KorrekteAntworten: Integer;
  FalscheAntworten: Integer;


Dann kommt auf die Form ein Startbutton. Mit sowas im OnClick-Event:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
Rundenzahl := 0;
KorrekteAntworten := 0;
AktuellerFaktor1 := Random(12) + 1;
LabelFaktor1.Caption := IntToStr(AktuellerFaktor1)
// andere Variablen entsprechend setzen


Nach dem Start-Button drückt man dann immer den Ergebnis-absenden-Button. In dessen OnClick-Event passiert dann das:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
if StrtoInt(EditEingabe.Text) = Faktor1 * Faktor2 then
begin
  // richtige Antwort
end else
begin
  // falsche Antwort
end;

Rundenzahl := Rundenzahl + 1;

if (Rundenzahl < 10) and (FalscheAntworten < 5) then
begin
  // neue Werte auswählen
  AktuellerFaktor1 := Random(12) + 1
  // ... usw
end else
begin
  Showmessage('Game over')
end


Das so als grober Aufbau

_________________
We are, we were and will not be.
Greek Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 45



BeitragVerfasst: Do 30.10.08 20:17 
ach man ich grig das einfach net hin -.-
Hidden
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2242
Erhaltene Danke: 55

Win10
VS Code, Delphi 2010 Prof.
BeitragVerfasst: Do 30.10.08 22:32 
Etwas detaillierter, bitte ;)

_________________
Centaur spears can block many spells, but no one tries to block if they see that the spell is a certain shade of green. For this purpose it is useful to know some green stunning hexes. (HPMoR)
Greek Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 45



BeitragVerfasst: So 02.11.08 14:14 
wo leg ich die variablen an?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
var 
  Rundenzahl: Integer; 
  AktuellerFaktor1: Integer; 
  AktuellerFaktor2: Integer; 
  KorrekteAntworten: Integer; 
  FalscheAntworten: Integer;


in einen der buttons nicht oder? wo muss das hin?

Moderiert von user profile iconChristian S.: Delphi-Tags hinzugefügt
Greek Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 45



BeitragVerfasst: So 02.11.08 16:16 
bitte helf mir, ich muss das heute noch meinem lehrer an seine email senden
Hidden
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2242
Erhaltene Danke: 55

Win10
VS Code, Delphi 2010 Prof.
BeitragVerfasst: So 02.11.08 16:24 
Hi,

Dann setz' dich am besten mal 15 Minuten hin und formuliere dein Problem klar. Auch, wenn die nötigen Informationen irgendwie da sind: Wenn das Lesen weniger "Widerstand" bietet, kommt man auch leichter mal zu einer Antwort ;)

Variablen deklarierst du am besten im Private-Teil der Form:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
type
  TForm1 = class(TForm)
  {..}
  private
    { private declarations }
    //hier ;)
  public
    { public declarations }
  end;

mfG,

_________________
Centaur spears can block many spells, but no one tries to block if they see that the spell is a certain shade of green. For this purpose it is useful to know some green stunning hexes. (HPMoR)
Greek Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 45



BeitragVerfasst: So 02.11.08 16:55 
Meine Frage war doch, wo ich die variablen hinsetzen muss, und du hast doch auch korrekt geantwortet, wo liegt den jetzt das Problem?

Hab die jetzt da hingesetzt und da stehen jetzt alles voller Errors
END erwartet aber Var gefunden
, oder : erwartet, aber end gefunden
. erwartet aber, aber implementation gefunden
ungenügend forward und external deklarationen
Jakob_Ullmann
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1747
Erhaltene Danke: 15

Win 7, *Ubuntu GNU/Linux*
*Anjuta* (C, C++, Python), Geany (Vala), Lazarus (Pascal), Eclipse (Java)
BeitragVerfasst: So 02.11.08 17:01 
Zur Not auch hier:

ausblenden Delphi-Quelltext
1:
2:
var
  Form1: TForm1;


rzahl1 und 2 deklarierst du lokal, oder aber so (ganz ohne Variablen):

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
procedure TForm1.Button1Click(Sender: TObject);
begin
  if IntToStr(Edit4.Text) < 10 then
  begin
    {
      ... - Prüfung ob richtig gerechnet und darauf reagieren
    }

    Edit1.Text := IntToStr(random(10) + 2);
    Edit2.Text := IntToStr(random(10) + 2);
    Edit4.Text := IntToStr(StrToInt(Edit4.Text) + 1);
  end else
  begin
    {
      ... - Auswertung
    }

  end;
end;


Bzw. für die Fehler solltest du Variablen einbauen.

EDIT: Anscheinend hast du irgendwo ein Semikolon vergessen oder ein end; zuviel oder sowas. Sende mal deinen Code, damit kann man relativ wenig anfangen. :D
Greek Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 45



BeitragVerfasst: So 02.11.08 17:08 
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:
unit Aufgabe2U;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private-Deklarationen }
  var
  Rundenzahl: Integer;
  AktuellerFaktor1: Integer;
  AktuellerFaktor2: Integer;
  KorrekteAntworten: Integer;
  FalscheAntworten: Integer;
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
Rundenzahl := 0; 
KorrekteAntworten := 0; 
AktuellerFaktor1 := Random(12) + 1;
LabelFaktor1.Caption := IntToStr(AktuellerFaktor1);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
if StrtoInt(EditEingabe.Text) = Faktor1 * Faktor2 then 
begin 
  // richtige Antwort 
end else 
begin 
  // falsche Antwort 
end; 


Rundenzahl := Rundenzahl + 1; 


if (Rundenzahl < 10) and (FalscheAntworten < 5) then 
begin 
  // neue Werte auswählen 
  AktuellerFaktor1 := Random(12) + 1 
  // ... usw 
end else 
begin 
  Showmessage('Game over') 
end
end;

end.


Ich kann delphi noch garnicht, nur so ganz einfaches zeug, weis garnet wie ich das machen soll
Timosch
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1314

Debian Squeeze, Win 7 Prof.
D7 Pers
BeitragVerfasst: So 02.11.08 17:19 
Mach das var unter private weg (Zeile 17).

_________________
If liberty means anything at all, it means the right to tell people what they do not want to hear. - George Orwell
Greek Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 45



BeitragVerfasst: So 02.11.08 17:43 
Gut jetzt sind nen paar fehler Weg...
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:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
<div class="syntaxContainer">  <div class="syntaxSelect">    <a class="genmed" style="text-decoration: none" href="javascript:selectAll(53153210)">markieren</a>  </div>  <div class="syntaxTitle genmed">        <a style="text-decoration: none" href="javascript:toggleCode(53153210)">            <span  id="minusFor53153210"><img class="codecollapse crispscaling" align="top" src="./graphics/bbcode/code_hide.png" border="0" alt="ausblenden" title="ausblenden"/></span>            <span style="display: none;" id="plusFor53153210"><img class="codecollapse crispscaling" align="top" src="./graphics/bbcode/code_show.png" border="0" alt="anzeigen" title="anzeigen"/></span>        </a>        <a style="text-decoration: none" href="javascript:toggleScroll(53153210,400)">  <span  id="fullFor53153210"><img class="codecollapse crispscaling" align="top" src="./graphics/bbcode/code_full.png" border="0" alt="volle Höhe" title="volle Höhe"/></span>   <span style="display: none;" id="halfFor53153210"><img class="codecollapse crispscaling" align="top" src="./graphics/bbcode/code_half.png" border="0" alt="reduzierte Höhe" title="reduzierte Höhe"/></span></a>        <b>Delphi-Quelltext</b>        <span class="copyright" style="display: none" id="hintFor53153210">                       </span>  </div>  <div id="code53153210" class="syntax" style=" height: 400px; ">    <table cellspacing="0" cellpadding="0">      <tr>        <td valign="top" style="text-align: right; padding-right: 3px; border: #DBE4EB solid; border-width: 0px 1px 0px 0px;">          <pre>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:
</pre>        </td>        <td valign="top" style="width: 100%; padding-left: 3px;">          <pre class="sourcecode"><span class="codekey">unit</span> Aufgabe2U;

<span class="codekey">interface</span>

<span class="codekey">uses</span>
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

<span class="codekey">type</span>
  TForm1 = <span class="codekey">class</span>(TForm)
    Button1: TButton;
    Button2: TButton;
    Faktor1: TLabel;
    EditEingabe: TEdit;
    <span class="codekey">procedure</span> Button1Click(Sender: TObject);
    <span class="codekey">procedure</span> Button2Click(Sender: TObject);
  <span class="codekey">private</span>
    <span class="codecomment">{ Private-Deklarationen }</span>
  Rundenzahl: Integer;
  AktuellerFaktor1: Integer;
  AktuellerFaktor2: Integer;
  KorrekteAntworten: Integer;
  FalscheAntworten: Integer;
  <span class="codekey">public</span>
    <span class="codecomment">{ Public-Deklarationen }</span>
  <span class="codekey">end</span>;

<span class="codekey">var</span>
  Form1: TForm1;

<span class="codekey">implementation</span>

<span class="codecompilerdirective">{$R *.DFM}</span>

<span class="codekey">procedure</span> TForm1.Button1Click(Sender: TObject);
<span class="codekey">begin</span>
Rundenzahl := <span class="codenumber">0</span>; 
KorrekteAntworten := <span class="codenumber">0</span>; 
AktuellerFaktor1 := Random(<span class="codenumber">12</span>) + <span class="codenumber">1</span>;
Faktor1.Caption := IntToStr(AktuellerFaktor1);
<span class="codekey">end</span>;

<span class="codekey">procedure</span> TForm1.Button2Click(Sender: TObject);
<span class="codekey">begin</span>
<span class="codekey">if</span> StrtoInt(EditEingabe.Text) = Faktor1 * Faktor2 <span class="codekey">then</span>
<span class="codekey">begin</span> 
  <span class="codecomment">// richtige Antwort
</span><span class="codekey">end</span> <span class="codekey">else</span> 
<span class="codekey">begin</span>
  <span class="codecomment">// falsche Antwort 
</span><span class="codekey">end</span>; 


Rundenzahl := Rundenzahl + <span class="codenumber">1</span>; 


<span class="codekey">if</span> (Rundenzahl < <span class="codenumber">10</span>) <span class="codekey">and</span> (FalscheAntworten < <span class="codenumber">5</span>) <span class="codekey">then</span> 
<span class="codekey">begin</span> 
  <span class="codecomment">// neue Werte auswählen 
</span>  AktuellerFaktor1 := Random(<span class="codenumber">12</span>) + <span class="codenumber">1</span> 
  <span class="codecomment">// ... usw 
</span><span class="codekey">end</span> <span class="codekey">else</span> 
<span class="codekey">begin</span> 
  Showmessage(<span class="codestring">'Game over'</span>) 
<span class="codekey">end</span>
<span class="codekey">end</span>;

<span class="codekey">end</span>.          </pre>        </td>      </tr>    </table>  </div></div>


Aber ohne ein paar tipps wie ich es jetzt weiter machen muss, blick ich da echt nicht mehr durch...

Moderiert von user profile iconChristian S.: Code- durch Delphi-Tags ersetzt
Hidden
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2242
Erhaltene Danke: 55

Win10
VS Code, Delphi 2010 Prof.
BeitragVerfasst: So 02.11.08 17:45 
Hi,

Nimm abm besten Delphi-Tags für Delphi-Quelltext(Statt code-Tags ;)

user profile iconGreek hat folgendes geschrieben Zum zitierten Posting springen:
Aber ohne ein paar tipps wie ich es jetzt weiter machen muss, blick ich da echt nicht mehr durch...
Welche Fehler bleiben denn noch? wo fehlt dir der Ansatz?

_________________
Centaur spears can block many spells, but no one tries to block if they see that the spell is a certain shade of green. For this purpose it is useful to know some green stunning hexes. (HPMoR)
Greek Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 45



BeitragVerfasst: So 02.11.08 17:54 
probiers doch ma aus , ich ne gui mit 2 buttons und einem laben names Faktor1 und eine edit feld mit dem namen Editeingabe, und was jetzt?
Greek Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 45



BeitragVerfasst: So 02.11.08 21:00 
3 Stunden spätestens abgabe, help!! was muss ich den jetzt weiter machen? mein code steht da
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: So 02.11.08 21:08 
user profile iconGreek hat folgendes geschrieben Zum zitierten Posting springen:
probiers doch ma aus
Stimmt, ist ja zu viel verlangt, dass Du die Fehler hinschreibst :roll:

user profile iconGreek hat folgendes geschrieben Zum zitierten Posting springen:
3 Stunden spätestens abgabe, help!! was muss ich den jetzt weiter machen? mein code steht da
Und wo kommst Du nicht weiter??? Was hast Du Dir die letzten Stunden für Gedanken gemacht? Was wolltest Du ins Programm einbauen? Wie hast Du es probiert? An welcher Stelle kamst Du nicht weiter?

Lass Dir doch nicht alles aus der Nase ziehen und vor allem zeig uns, dass Du selber dran arbeitest und nicht immer nur erwartest, dass man Dir hier alles vorkaut!

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Greek Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 45



BeitragVerfasst: So 02.11.08 22:05 
Ihr versteht das nicht, Ich kann keine Delphi!! 0% ich kann das überhaupt noch nicht!

Ich glaub unserer lehrer hat sich verguckt als er uns die Aufgabe gegeben hat, und wie weit ich gekommen bin steht ja oben. Ich versteh noch net mal was da steht.. Wir hatten gerade mal nen Taschenrechner gemacht und da müsste man ja fast garnix machen, weil er ihn eh fast komplet an die Tafel geschrieben hat.
Dieses Thema ist gesperrt, Du kannst keine Beiträge editieren oder beantworten.

Das Thema wurde von einem Team-Mitglied geschlossen. Wenn du mit der Schließung des Themas nicht einverstanden bist, kontaktiere bitte das Team.