<?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[mit double von negativem Startwert hochzählen]]></title><description><![CDATA[<p>Ich will von -1.0 bis 0 in Schritten von 0.1 hochzählen</p>
<p>mein Vorschlag:</p>
<p>//---------------------------------------------------------------------------</p>
<p>#include &lt;vcl.h&gt;<br />
#include &lt;iostream.h&gt;<br />
#pragma hdrstop</p>
<p>//---------------------------------------------------------------------------</p>
<p>#pragma argsused<br />
int main(int argc, char* argv[])<br />
{<br />
for (double n=-1.0; n=0 ; n=n+0.1)<br />
{<br />
cout&lt;&lt; n &lt;&lt;endl;<br />
}<br />
return 0;<br />
}<br />
//---------------------------------------------------------------------------</p>
<p>kommt aber nicht's blitzt nur kurz ein fenster auf, wo liegt der fehler ?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/272264/mit-double-von-negativem-startwert-hochzählen</link><generator>RSS for Node</generator><lastBuildDate>Fri, 28 Aug 2026 22:18:02 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/272264.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 13 Aug 2010 16:05:21 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to mit double von negativem Startwert hochzählen on Fri, 13 Aug 2010 16:05:21 GMT]]></title><description><![CDATA[<p>Ich will von -1.0 bis 0 in Schritten von 0.1 hochzählen</p>
<p>mein Vorschlag:</p>
<p>//---------------------------------------------------------------------------</p>
<p>#include &lt;vcl.h&gt;<br />
#include &lt;iostream.h&gt;<br />
#pragma hdrstop</p>
<p>//---------------------------------------------------------------------------</p>
<p>#pragma argsused<br />
int main(int argc, char* argv[])<br />
{<br />
for (double n=-1.0; n=0 ; n=n+0.1)<br />
{<br />
cout&lt;&lt; n &lt;&lt;endl;<br />
}<br />
return 0;<br />
}<br />
//---------------------------------------------------------------------------</p>
<p>kommt aber nicht's blitzt nur kurz ein fenster auf, wo liegt der fehler ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1939719</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1939719</guid><dc:creator><![CDATA[Geli]]></dc:creator><pubDate>Fri, 13 Aug 2010 16:05:21 GMT</pubDate></item><item><title><![CDATA[Reply to mit double von negativem Startwert hochzählen on Fri, 13 Aug 2010 16:11:06 GMT]]></title><description><![CDATA[<p>Schau mal was du in der Schleife für eine Bedinung für den Abbruch hast. Ist das überhaupt ein Vergleich?</p>
<p>btw:<br />
Wenn das ein korrekter Vergleich wäre, dann hättest du gerade das Gegenteil von dem jetztigen Zustand. Die Schleife wird wahrscheinlich nicht terminieren, weil ein direkter Vergleich von Flieskommazahlen oftmals nicht funktioniert (Ich rate da eher zu &gt;=, anstatt == ).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1939721</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1939721</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Fri, 13 Aug 2010 16:11:06 GMT</pubDate></item><item><title><![CDATA[Reply to mit double von negativem Startwert hochzählen on Fri, 13 Aug 2010 16:14:12 GMT]]></title><description><![CDATA[<p><a href="http://c-plusplus.net/forum/viewtopic-var-t-is-111042.html" rel="nofollow">http://c-plusplus.net/forum/viewtopic-var-t-is-111042.html</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1939722</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1939722</guid><dc:creator><![CDATA[Blitz]]></dc:creator><pubDate>Fri, 13 Aug 2010 16:14:12 GMT</pubDate></item><item><title><![CDATA[Reply to mit double von negativem Startwert hochzählen on Fri, 13 Aug 2010 16:15:05 GMT]]></title><description><![CDATA[<p>Geli schrieb:</p>
<blockquote>
<p>kommt aber nicht's blitzt nur kurz ein fenster auf, wo liegt der fehler ?</p>
</blockquote>
<p>Die meistgestellten Fragen, #2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1939723</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1939723</guid><dc:creator><![CDATA[Michael E.]]></dc:creator><pubDate>Fri, 13 Aug 2010 16:15:05 GMT</pubDate></item><item><title><![CDATA[Reply to mit double von negativem Startwert hochzählen on Fri, 13 Aug 2010 16:18:23 GMT]]></title><description><![CDATA[<p>n=0 ist eine Zuweisung und kein Vergleich. Diese Zuweisung, wenn man sie zu bool konvertiert, liefert immer false. Zu dem zweiten Teil der for-Schleife sagt man zwar &quot;Abbruchbedingung&quot;, aber das ist von Dir anscheinend falsch verstanden worden. Die Schleife wird abgebrochen, wenn die Bedingung false ist. Daher läuft das, was in der Schleife steht nie. Wenn man das korrigiert, würde es so aussehen:</p>
<pre><code class="language-cpp">for (double n=-1; n&lt;=0; n=n+0.1)
</code></pre>
<p>Aber selbst das ist zumindest ungeschickt, da das Rechnen mit double Rundungsfehler mit sich bringt. Die Zahl 0,1 ist auch nicht exakt darstellbar. Das heißt, dass Du eventuell die 0 nicht mehr mitnimmst, da n in der &quot;letzten Iteration&quot; 0,0000000000000003124235 oder so etwas sein könnte, was ja größer als 0 ist.</p>
<p>Bzgl &quot;kurz aufblitzen&quot; guck bitte hier in der FAQ nach.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1939724</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1939724</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Fri, 13 Aug 2010 16:18:23 GMT</pubDate></item><item><title><![CDATA[Reply to mit double von negativem Startwert hochzählen on Fri, 13 Aug 2010 16:30:29 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/24868">@krümelkacker</a><br />
Warum sollte das so nicht gut sein? Du hast ja ein &lt;= und kein == drin.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1939730</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1939730</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Fri, 13 Aug 2010 16:30:29 GMT</pubDate></item><item><title><![CDATA[Reply to mit double von negativem Startwert hochzählen on Fri, 13 Aug 2010 16:38:18 GMT]]></title><description><![CDATA[<p>drakon schrieb:</p>
<blockquote>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/24868">@krümelkacker</a><br />
Warum sollte das so nicht gut sein? Du hast ja ein &lt;= und kein == drin.</p>
</blockquote>
<p>Aber -1 + 10 * 0.1 könnte &gt;0 sein. Falls man beabsichtigt die 0 noch mitzunehmen, sollte man sicherheitshalber auf &lt;(0 + halbe_schrittweite) prüfen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1939736</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1939736</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Fri, 13 Aug 2010 16:38:18 GMT</pubDate></item><item><title><![CDATA[Reply to mit double von negativem Startwert hochzählen on Fri, 13 Aug 2010 16:48:29 GMT]]></title><description><![CDATA[<p>Hmm. Ok.<br />
Kommt wohl drauf an, was man mit der Schleife beabsichtigt zu tun.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1939740</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1939740</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Fri, 13 Aug 2010 16:48:29 GMT</pubDate></item><item><title><![CDATA[Reply to mit double von negativem Startwert hochzählen on Fri, 13 Aug 2010 16:53:37 GMT]]></title><description><![CDATA[<p>drakon schrieb:</p>
<blockquote>
<p>Hmm. Ok.<br />
Kommt wohl drauf an, was man mit der Schleife beabsichtigt zu tun.</p>
</blockquote>
<p>Ja, normalerweise würde man das ja auch anders schreiben, weil &lt;= bei for-Schleifen als Abbruchbedingung unüblich ist. Aber auch dann ist es gefährlich nur &lt;0 zu schreiben, wenn die 0 nicht mitgenommen werden soll, aus den gleichen Gründen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1939744</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1939744</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Fri, 13 Aug 2010 16:53:37 GMT</pubDate></item><item><title><![CDATA[Reply to mit double von negativem Startwert hochzählen on Fri, 13 Aug 2010 17:25:32 GMT]]></title><description><![CDATA[<p>Mit &lt;0 als Abbruchbedingung bekomme ich nach -0.1 noch eine -1.38778e-16<br />
<a href="http://codepad.org/olSnuWrd" rel="nofollow">http://codepad.org/olSnuWrd</a></p>
<p>kk</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1939754</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1939754</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Fri, 13 Aug 2010 17:25:32 GMT</pubDate></item><item><title><![CDATA[Reply to mit double von negativem Startwert hochzählen on Sat, 14 Aug 2010 17:30:07 GMT]]></title><description><![CDATA[<p>Für double-Werte nimmt man besser eine while-Schleife. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1940054</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1940054</guid><dc:creator><![CDATA[berniebutt]]></dc:creator><pubDate>Sat, 14 Aug 2010 17:30:07 GMT</pubDate></item><item><title><![CDATA[Reply to mit double von negativem Startwert hochzählen on Sat, 14 Aug 2010 19:34:39 GMT]]></title><description><![CDATA[<p>berniebutt schrieb:</p>
<blockquote>
<p>Für double-Werte nimmt man besser eine while-Schleife. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
</blockquote>
<p>Was kann die while-Schleife denn besser? Hmm?</p>
<p>In diesem Fall sollte der Code eher so aussehen:</p>
<pre><code class="language-cpp">for (int i=-10; i&lt;=0; ++i) {
  cout &lt;&lt; i/10.0 &lt;&lt; endl;
}
</code></pre>
<p>Klar, mit'ner while-Schleife kannst Du das auch machen, wenn Du willst. Viel besser wird's dadurch aber nicht...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1940079</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1940079</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Sat, 14 Aug 2010 19:34:39 GMT</pubDate></item><item><title><![CDATA[Reply to mit double von negativem Startwert hochzählen on Sun, 15 Aug 2010 00:37:22 GMT]]></title><description><![CDATA[<p>[cpp]for (int <strong>i=-10;</strong> i&lt;=0; ++i) {[/cpp]</p>
<p>stimmt das? sieht irgendwie nach</p>
<pre><code class="language-cpp">int i = i - 1;
</code></pre>
<p>aus, habs aber nicht ausprobiert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1940151</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1940151</guid><dc:creator><![CDATA[lorn]]></dc:creator><pubDate>Sun, 15 Aug 2010 00:37:22 GMT</pubDate></item><item><title><![CDATA[Reply to mit double von negativem Startwert hochzählen on Mon, 16 Aug 2010 09:57:27 GMT]]></title><description><![CDATA[<p>krümelkacker schrieb:</p>
<blockquote>
<p>berniebutt schrieb:</p>
<blockquote>
<p>Für double-Werte nimmt man besser eine while-Schleife. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
</blockquote>
<p>Was kann die while-Schleife denn besser? Hmm? ...</p>
<p>Klar, mit'ner while-Schleife kannst Du das auch machen, wenn Du willst. Viel besser wird's dadurch aber nicht...</p>
</blockquote>
<p>Dann nimm doch gleich die BASIC-Interpreter-Methode mit gotos. Kannst auch alles mit machen - musst allein etwas mehr nachdenken! :p</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1940508</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1940508</guid><dc:creator><![CDATA[berniebutt]]></dc:creator><pubDate>Mon, 16 Aug 2010 09:57:27 GMT</pubDate></item></channel></rss>