<?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[While so lange bis sich ein Wert nicht verändert]]></title><description><![CDATA[<p>Habe ein Problem: Und zwar will ich etwas in eine while Schleife schreiben und das soll aber nur so lange ausgegeben werden, bis der wert den ich ausgeben will sich nicht mehr verändert.<br />
Wäre sehr nett wenn mir jemand helfen könnte <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p>MfG</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/328267/while-so-lange-bis-sich-ein-wert-nicht-verändert</link><generator>RSS for Node</generator><lastBuildDate>Wed, 08 Jul 2026 03:40:19 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/328267.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 30 Sep 2014 15:45:10 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to While so lange bis sich ein Wert nicht verändert on Tue, 30 Sep 2014 15:45:10 GMT]]></title><description><![CDATA[<p>Habe ein Problem: Und zwar will ich etwas in eine while Schleife schreiben und das soll aber nur so lange ausgegeben werden, bis der wert den ich ausgeben will sich nicht mehr verändert.<br />
Wäre sehr nett wenn mir jemand helfen könnte <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p>MfG</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2420097</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2420097</guid><dc:creator><![CDATA[c++Freak12345]]></dc:creator><pubDate>Tue, 30 Sep 2014 15:45:10 GMT</pubDate></item><item><title><![CDATA[Reply to While so lange bis sich ein Wert nicht verändert on Tue, 30 Sep 2014 15:50:43 GMT]]></title><description><![CDATA[<p>Kam mir jetzt so als erstes in den Sinn.</p>
<pre><code>int wert = 0;
int wertAlt = 0;
do
{
    wertAlt = wert;
    aenderWert(&amp;wert);
} while (wert != wertAlt)
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2420098</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2420098</guid><dc:creator><![CDATA[coder++]]></dc:creator><pubDate>Tue, 30 Sep 2014 15:50:43 GMT</pubDate></item><item><title><![CDATA[Reply to While so lange bis sich ein Wert nicht verändert on Tue, 30 Sep 2014 15:56:43 GMT]]></title><description><![CDATA[<p>Geht das auch nur mit while? Also ohne do?</p>
<p>z.b</p>
<pre><code>int a
int b
while (a&gt;=b) {
*Rechnung*
cout&lt;&lt;a;
cout&lt;&lt;b; 
}
</code></pre>
<p>so hierbei ist zu beachten dass a immer größer als b bleibt. Also will ich a und b solange ausgeben bis der wert sich für a und b verändert. Wenn der irgendwann gleich bleibt, soll das nicht mehr ausgegeben werden.</p>
<p>MfG</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2420099</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2420099</guid><dc:creator><![CDATA[c++Freak12345]]></dc:creator><pubDate>Tue, 30 Sep 2014 15:56:43 GMT</pubDate></item><item><title><![CDATA[Reply to While so lange bis sich ein Wert nicht verändert on Tue, 30 Sep 2014 16:06:09 GMT]]></title><description><![CDATA[<p>Klar.<br />
Aber dann müssen a und b mit unterschiedlichen Werten initialisiert werden, da sonst die Schleife nicht ein einziges mal ausgeführt wird.<br />
Außerdem: Semikolon hinter Befehlen nicht vergessen!<br />
Also so sollte es dann ungefähr aussehen:</p>
<pre><code>int a = 0; // Anstelle von 0 dein Startwert
int b = a + 1;
while (a &gt;= b) 
{
    std::cout &lt;&lt; a;
    std::cout &lt;&lt; b; 
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2420101</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2420101</guid><dc:creator><![CDATA[coder++]]></dc:creator><pubDate>Tue, 30 Sep 2014 16:06:09 GMT</pubDate></item><item><title><![CDATA[Reply to While so lange bis sich ein Wert nicht verändert on Tue, 30 Sep 2014 16:04:21 GMT]]></title><description><![CDATA[<p>Erkläre mal was du konkret haben möchtest und präsentiere deinen Lösungsvorschlag Vorschlag (als anständig formatiertes, kompilierbares Programm).</p>
<p>PS: Es git mit <code>while</code> , <code>do while</code> oder <code>for</code> . Jenachdem was du konkret brauchst ist eine der Schleifen eleganter als die anderen aber im Prinzip funktionieren alle.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2420102</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2420102</guid><dc:creator><![CDATA[icarus2]]></dc:creator><pubDate>Tue, 30 Sep 2014 16:04:21 GMT</pubDate></item><item><title><![CDATA[Reply to While so lange bis sich ein Wert nicht verändert on Tue, 30 Sep 2014 16:13:41 GMT]]></title><description><![CDATA[<p>Also hier mal mein Programm:</p>
<pre><code>int anzahl,maximal_anzahl,jahr,differenz;
anzahl=50;
maximal_anzahl=350;
jahr=0;
 while (maximal_anzahl&gt;=a) {
        differenz=maximal_anzahl-anzahl;
        anzahl=anzahl+(differenz*6/100); //weil pro jahr werden es 6% von der           differenz  mehr

        jahr++;
     cout&lt;&lt;jahr;
     cout&lt;&lt;anzahl;
 }
</code></pre>
<p>so und jetzt gibt er es unendlich lange aus. Wie kann ich das denn verhindern? Also wie gesagt dass a und b nur so lange ausgegeben werden, solange sie sich verändern.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2420104</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2420104</guid><dc:creator><![CDATA[c++Freak12345]]></dc:creator><pubDate>Tue, 30 Sep 2014 16:13:41 GMT</pubDate></item><item><title><![CDATA[Reply to While so lange bis sich ein Wert nicht verändert on Tue, 30 Sep 2014 16:56:40 GMT]]></title><description><![CDATA[<p>Wenn du nach while a durch jahr ersetzt sollte es gehen.<br />
Für diesen Fall würde ich dir aber eine for-Schleife empfehlen.<br />
Achja:</p>
<pre><code>anzahl=anzahl+(differenz*6/100);
</code></pre>
<p>Würde ich durch</p>
<pre><code>anzahl += (differenz*6/100);
</code></pre>
<p>ersetzen.<br />
Der Maschinencode wird zwar glaub ich der gleiche sein, aber ist meiner Meinung nach lesbarer.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2420111</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2420111</guid><dc:creator><![CDATA[coder++]]></dc:creator><pubDate>Tue, 30 Sep 2014 16:56:40 GMT</pubDate></item><item><title><![CDATA[Reply to While so lange bis sich ein Wert nicht verändert on Tue, 30 Sep 2014 17:05:52 GMT]]></title><description><![CDATA[<p>Nein so klappt es leider nicht. Es wird zwar nicht mehr unendlich aber bei Jahr kommt immer noch was zu großes raus. Ich will ja wissen nach wie vielen Jahren die maximal Anzahl (350) mit einer Wachstumsrate von 6% ,von der Differenz von maximal Anzahl und anzahl, pro Jahr, erreicht ist.<br />
Und sorry hab mich verschrieben: nach while sollte nicht a sondern anzahl stehen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2420114</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2420114</guid><dc:creator><![CDATA[c++Freak12345]]></dc:creator><pubDate>Tue, 30 Sep 2014 17:05:52 GMT</pubDate></item><item><title><![CDATA[Reply to While so lange bis sich ein Wert nicht verändert on Tue, 30 Sep 2014 17:39:17 GMT]]></title><description><![CDATA[<p>Ich seh jetzt keinen Fehler.<br />
Wieviel Jahre hast denn raus?<br />
Also wieviel gibt dir das Programm aus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2420119</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2420119</guid><dc:creator><![CDATA[coder++]]></dc:creator><pubDate>Tue, 30 Sep 2014 17:39:17 GMT</pubDate></item><item><title><![CDATA[Reply to While so lange bis sich ein Wert nicht verändert on Tue, 30 Sep 2014 18:22:42 GMT]]></title><description><![CDATA[<p>Nach 351 Jahren 334 Anzahl. Aber nach 350 Jahren sind es auch 334..</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2420121</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2420121</guid><dc:creator><![CDATA[c++Freak12345]]></dc:creator><pubDate>Tue, 30 Sep 2014 18:22:42 GMT</pubDate></item><item><title><![CDATA[Reply to While so lange bis sich ein Wert nicht verändert on Tue, 30 Sep 2014 18:39:51 GMT]]></title><description><![CDATA[<p>Guck dir mal deine typen an. Ohne genauer zu prüfen, bezweifel ich mal das int der richtige Typ für alle Variablen ist - zumindest schneidest du mit</p>
<pre><code>anzahl=anzahl+(differenz*6/100);
</code></pre>
<p>da ein paar Nachkommastellen ab, und das dürfte gerade bei Prozentrechnen nicht in deinem Sinn sein.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2420124</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2420124</guid><dc:creator><![CDATA[kleiner Troll]]></dc:creator><pubDate>Tue, 30 Sep 2014 18:39:51 GMT</pubDate></item><item><title><![CDATA[Reply to While so lange bis sich ein Wert nicht verändert on Tue, 30 Sep 2014 18:46:25 GMT]]></title><description><![CDATA[<p>Wie schon gesagt, die Differenz wird immer kleiner... bis sie bei 16 so klein ist, das die 6% kleiner als eins wird und somit eine null im <code>int</code> steht.</p>
<p>Wenn das so gewollt ist, sowas in der Art?:</p>
<pre><code>int main(int argc, char *argv[]) 
{ 
	int anzahl = 50, maximal_anzahl = 350, jahr = 0;

	while (true) {
		int anzahl_alt = anzahl;

		int differenz = maximal_anzahl - anzahl;
		anzahl += differenz*6/100;

		if (anzahl == anzahl_alt)
			break;

		jahr++;

		cout &lt;&lt; jahr &lt;&lt; &quot;. Jahr =&gt; Anzahl = &quot; &lt;&lt; anzahl &lt;&lt; endl;
	}
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2420127</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2420127</guid><dc:creator><![CDATA[lagalopex]]></dc:creator><pubDate>Tue, 30 Sep 2014 18:46:25 GMT</pubDate></item></channel></rss>