Autor Beitrag
Paulchengb
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 39



BeitragVerfasst: Di 14.08.07 11:49 
Hallo,

wie kann ich denn den Wert einer Zahl um die Anzahl erhöhen, so oft die Bedingung erreicht wird?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
if <Bedingung>
then

z:= 1++;


Aber das funktioniert nicht. Da ist das ; nach den beiden ++ rot unterringelt --> Syntaxfehler...


Moderiert von user profile iconGausi: Topic aus VCL (Visual Component Library) verschoben am Di 14.08.2007 um 11:52
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Di 14.08.07 11:52 
In Delphi gibts kein ++. Hier kann man das so machen:  z := z + 1; oder inc(z);.

_________________
We are, we were and will not be.
Paulchengb Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 39



BeitragVerfasst: Di 14.08.07 11:57 
Hi,
danke. Das geht jetzt schonmal, aber die Operation wird nur 1x ausgeführt...

Also ich erstelle 10 Zufallszahlen und folgende Eigenschaften sollen erfüllt sein:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
if (v<=x) and (x<=b) and (v<=y) and (y<=b) and (v<=z) and (z<=b) then

p:= p + 1;

labelededit5.Text:=floattostr (p);
end;


x,y,z sind die 1.,2.,3. Stelle der Zufallszahl und v=von b=bis, welche Ziffern enthalten sein sollen, z.B. v=3, b=6 --> es sollen nur die Zufallszahlen gezählt werden, die 3,4,5 und 6 enthalten.
pigfacejoe
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 332
Erhaltene Danke: 1

Win 10, Ubuntu
Delphi,Javascript, PHP, Java, Python
BeitragVerfasst: Di 14.08.07 12:07 
Da brauchste ne Wiederholungsanweisung, so wie ich das verstehe.
In diesem Fall würde sich da ja eine for Anweisung anbieten.
Also in etwa so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
for p:= v to b do
begin
//DEine Überprüfungen,p darf nicht erhöht werden , geschieht automatisch
end;

So sollte das klappen,

Schönen Gruss
Pigface Joe
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Di 14.08.07 12:09 
Moin!

Dein Ansatz ist falsch, vielleicht geht es besser so:
- Eine Schleife, die über alle erzeugten Zufallszahlen läuft
- Eine innere Schleife, die über die Stellen der aktuellen Zufallszahl läuft
- in dieser Schleife prüfen, ob die aktuelle Ziffer der aktuellen Zufallszahl im gesuchten Bereich liegt: das geht z.B. so: if (StelleInZufallszahl[Position] in ['3'..'6']) then
:idea:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
TheAxeEffect
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 37



BeitragVerfasst: Di 14.08.07 19:21 
was meinst du denn?
meinst so solange etwas so ist wie es sein soll, soll er es erhöhen, oder er soll es x-mal erhöhen oder er soll x mal prüfen, ob etwas so ist wie es sein soll, und ggf. erhöhen?
fall 1:
ausblenden Delphi-Quelltext
1:
2:
3:
while (bedingung) do begin
p:=p+1//oder inc(p)
end;

fall 2:
ausblenden Delphi-Quelltext
1:
2:
3:
for loop-variable(zb. i):=1 to x do begin
inc(p);
end;

fall3:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
<div class="syntaxContainer">  <div class="syntaxSelect">    <a class="genmed" style="text-decoration: none" href="javascript:selectAll(45649830)">markieren</a>  </div>  <div class="syntaxTitle genmed">        <a style="text-decoration: none" href="javascript:toggleCode(45649830)">            <span  id="minusFor45649830"><img class="codecollapse crispscaling" align="top" src="./graphics/bbcode/code_hide.png" border="0" alt="ausblenden" title="ausblenden"/></span>            <span style="display: none;" id="plusFor45649830"><img class="codecollapse crispscaling" align="top" src="./graphics/bbcode/code_show.png" border="0" alt="anzeigen" title="anzeigen"/></span>        </a>                <b>Delphi-Quelltext</b>        <span class="copyright" style="display: none" id="hintFor45649830">                       </span>  </div>  <div id="code45649830" class="syntax" style=" ">    <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:
</pre>        </td>        <td valign="top" style="width: 100%; padding-left: 3px;">          <pre class="sourcecode"><span class="codekey">for</span> loop-variable(zb. i):=<span class="codenumber">1</span> <span class="codekey">to</span> x <span class="codekey">do</span> <span class="codekey">begin</span>
<span class="codekey">if</span> bedingung <span class="codekey">then</span> <span class="codekey">begin</span>
inc(p);
<span class="codekey">end</span>;
<span class="codekey">end</span>;          </pre>        </td>      </tr>    </table>  </div></div>

oder meinst du überhaupt was anderes?
Paulchengb Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 39



BeitragVerfasst: Di 14.08.07 19:58 
@TheAxeEffect,
ich mein, dass wenn ich schon 10 Zufallszahlen erstellt habe, dann gibt es die ja. :P Nun sollen die 10 erstellen Zahlen auf "Bedingungen" überprüft werden, zB., dass sie nur die Ziffern 1-3 enthalten. Verstehst? Also so wie ich das lese, ist Fall 3 das richtige für mich. Ich habe das jetzt auch mal versucht, nur leider wird mir in dem edit.text Feld nichts ausgegeben. Es bleibt einfach leer.

Hier der Code:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
// Prozentsatz ausrechnen
for i:= 1 to x do
begin
if (v<=x) and (x<=b) and (v<=y) and (y<=b) and (v<=z) and (z<=b) then
begin
p:= p+1;
labelededit5.Text:=floattostr (p);
end;
end;
end;
TheAxeEffect
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 37



BeitragVerfasst: Di 14.08.07 20:04 
du weißt eh, dass du diese ausgabe in der schleife eingebunden hast oder?
du willst aber nur das endergebnis oder?
mach die mal aus der schleife raus.
dann: hast die die variable x deklariert, und definiert..wenn du mit der nix machst ist die 0, und die schleife geht erst garnich los.
edit: wo liegen deine zufallszahlen überhaupt? und: könnteste den ganzen code posten, dann wären wir eher imstande dir weiterzuhelfen^^
mfg,
simon
Paulchengb Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 39



BeitragVerfasst: Mi 15.08.07 12:31 
Danke für eure Hilfe. Ich habe es heute hinbekommen...