<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Einfache If-Schleife?!]]></title><description><![CDATA[<p>Hallo, ich bin neu und programmiere noch nicht lange mit C++, hab jetzt aber ein Problem, dass ich nicht lösen kann.</p>
<pre><code class="language-cpp">if (CheckBox1) {
	int i2=2000;}else{
		int i2=StrToInt(Edit2-&gt;Text);}
</code></pre>
<p>/E: Klappt jetzt, habe den Quelltext geändert:</p>
<pre><code class="language-cpp">{
	int i2=5;
	int i1=StrToInt(Edit1-&gt;Text);
	if (CheckBox1) {
		i2=800;}else{
		i2=StrToInt(Edit2-&gt;Text);}
	Beep(i1,i2);
}
</code></pre>
<p>Allerdings ändert er i2 nicht, wenn ich die Checkbox1 checke oder abwähle, wieso?</p>
<p>Lieben Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/255094/einfache-if-schleife</link><generator>RSS for Node</generator><lastBuildDate>Sat, 12 Sep 2026 06:28:59 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/255094.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 25 Nov 2009 16:31:46 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Einfache If-Schleife?! on Wed, 25 Nov 2009 16:41:07 GMT]]></title><description><![CDATA[<p>Hallo, ich bin neu und programmiere noch nicht lange mit C++, hab jetzt aber ein Problem, dass ich nicht lösen kann.</p>
<pre><code class="language-cpp">if (CheckBox1) {
	int i2=2000;}else{
		int i2=StrToInt(Edit2-&gt;Text);}
</code></pre>
<p>/E: Klappt jetzt, habe den Quelltext geändert:</p>
<pre><code class="language-cpp">{
	int i2=5;
	int i1=StrToInt(Edit1-&gt;Text);
	if (CheckBox1) {
		i2=800;}else{
		i2=StrToInt(Edit2-&gt;Text);}
	Beep(i1,i2);
}
</code></pre>
<p>Allerdings ändert er i2 nicht, wenn ich die Checkbox1 checke oder abwähle, wieso?</p>
<p>Lieben Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1813429</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1813429</guid><dc:creator><![CDATA[xLz3]]></dc:creator><pubDate>Wed, 25 Nov 2009 16:41:07 GMT</pubDate></item><item><title><![CDATA[Reply to Einfache If-Schleife?! on Wed, 25 Nov 2009 16:41:57 GMT]]></title><description><![CDATA[<p>Die Ursache für den Fehler zeigst du nicht im Code. Die beiden Warnings meinen genau, was sie sagen. Du hast einer Variable einen Wert zugewiesen, den/die du nie verwendest. Der Compiler warnt, weil solche Stellen oft auf Schreibfehler hinweisen. Er meint also, dass du etwas geschrieben hast, das du gar nicht meinst.</p>
<p>In deinem Fall vermute ich, dass du nicht verstehst, was jedes dieser Statments bewirkt: Du legst jedes Mal eine <em>neue</em> Variable an und weist ihr einen Wert zu. Wenn das Programm den Scope (die geschweifte Klammer-Ebene) verlässt, wird die Variable gelöscht. Vielleicht meinst du das:</p>
<pre><code class="language-cpp">int i2;
if (CheckBox1) {
   i2=2000;    // Verwendet die Variable i2 von oben
}
else {
   i2=StrToInt(Edit2-&gt;Text);  // dito
}	

// ...

if(i2 == 2000) {
   // ...
}
</code></pre>
<p>Stefan.</p>
<p>P.S.: Im Falle von if() spricht man übrigens nicht von &quot;Schleife&quot;, sondern von &quot;Bedingung&quot;.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1813434</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1813434</guid><dc:creator><![CDATA[DStefan]]></dc:creator><pubDate>Wed, 25 Nov 2009 16:41:57 GMT</pubDate></item><item><title><![CDATA[Reply to Einfache If-Schleife?! on Wed, 25 Nov 2009 16:42:48 GMT]]></title><description><![CDATA[<p>Abgesehen von der grauslichen Formatierung und dem grauslichen Wort &quot;If-Schleife&quot; <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_down"
      title=":-1:"
      alt="👎"
    /> ,<br />
Du erschaffst eine Variable, die nach der &quot;Schleife&quot; weg ist. Du kannst sie nur in der &quot;Schleife&quot; nutzen. Willst Du sie auch danach noch nutzen, musst Du sie vorher deklarieren.<br />
also so (mit neuer fOrmatierúng):</p>
<pre><code class="language-cpp">int i2 = 0;
if (CheckBox1) {
    i2=2000;
}
else {
    i2=StrToInt(Edit2-&gt;Text);
}
//Hier kannst Du i2 weiter nutzen, bis die Funktion verlassen wird.
</code></pre>
<p>EDIT: Man, bin ich langsam: zwei Leute schneller <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f62e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_open_mouth"
      title=":open_mouth:"
      alt="😮"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1813435</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1813435</guid><dc:creator><![CDATA[Mr X]]></dc:creator><pubDate>Wed, 25 Nov 2009 16:42:48 GMT</pubDate></item><item><title><![CDATA[Reply to Einfache If-Schleife?! on Wed, 25 Nov 2009 16:42:39 GMT]]></title><description><![CDATA[<p>entweder über eine Fkt, die nen int zurückgibt(in abhängigkeit davon, ob die checkbox gesetzt ist) oder du nutzt den ternären operator(für programmieranfänger vll nicht unbedingt übersichtlich, aber ok^^):</p>
<pre><code class="language-cpp">int get_foo()
{
  if(CheckBox-&gt;checked())
    return 2000;

  return StrToInt(bar-&gt;Text());
}

//anwendung:

int x = get_foo();
</code></pre>
<p>oder</p>
<pre><code class="language-cpp">int x = CehckBox-&gt;checked() ? 2000 : StrToInt(bar-&gt;Text());
</code></pre>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1813436</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1813436</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Wed, 25 Nov 2009 16:42:39 GMT</pubDate></item><item><title><![CDATA[Reply to Einfache If-Schleife?! on Wed, 25 Nov 2009 17:06:40 GMT]]></title><description><![CDATA[<p>Hey,<br />
Danke für die viele Hilfe, klappt jetzt.<br />
Juhu <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>Lieben Gruß.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1813453</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1813453</guid><dc:creator><![CDATA[xLz3]]></dc:creator><pubDate>Wed, 25 Nov 2009 17:06:40 GMT</pubDate></item><item><title><![CDATA[Reply to Einfache If-Schleife?! on Wed, 25 Nov 2009 17:22:28 GMT]]></title><description><![CDATA[<p><a href="http://if-schleife.de/" rel="nofollow">http://if-schleife.de/</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1813461</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1813461</guid><dc:creator><![CDATA[Kóyaánasqatsi]]></dc:creator><pubDate>Wed, 25 Nov 2009 17:22:28 GMT</pubDate></item></channel></rss>