<?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[zufallszahlen &#x2F; ausgabe als double]]></title><description><![CDATA[<p>hallo,</p>
<p>habe ein Programm geschrieben, welches den Mittelwert von Zufallszahlen ausgeben soll.</p>
<pre><code class="language-cpp">int *array = new int[anzahl];

    srand(time(0)); 

    //Generieren von Zufallszahlen
    for(int i=0; i&lt;anzahl; i++)
    {
     array[i] = 1+(rand()%100);
    }

    //Berechnung des Mittelwertes
    int temp;
    for(int a=0; a&lt;anzahl; a++)
    {
     temp += array[a];         
    }        

    double mittelwert = (temp / anzahl);
    cout&lt;&lt; endl;
    cout&lt;&lt; &quot;Der Gesamtwert betraegt: &quot; &lt;&lt; temp &lt;&lt;endl;
    cout&lt;&lt; &quot;Der Mittelwert betraegt: &quot; &lt;&lt; mittelwert &lt;&lt;endl;
    cout&lt;&lt; endl;
</code></pre>
<p>jetzt bekomm ich immer integerwerte raus.<br />
Was habe ich falsch gemacht? Es sollte eigentlich ein double-Wert sein!</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/170441/zufallszahlen-ausgabe-als-double</link><generator>RSS for Node</generator><lastBuildDate>Thu, 17 Sep 2026 02:45:03 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/170441.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 16 Jan 2007 09:34:28 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to zufallszahlen &#x2F; ausgabe als double on Tue, 16 Jan 2007 09:34:28 GMT]]></title><description><![CDATA[<p>hallo,</p>
<p>habe ein Programm geschrieben, welches den Mittelwert von Zufallszahlen ausgeben soll.</p>
<pre><code class="language-cpp">int *array = new int[anzahl];

    srand(time(0)); 

    //Generieren von Zufallszahlen
    for(int i=0; i&lt;anzahl; i++)
    {
     array[i] = 1+(rand()%100);
    }

    //Berechnung des Mittelwertes
    int temp;
    for(int a=0; a&lt;anzahl; a++)
    {
     temp += array[a];         
    }        

    double mittelwert = (temp / anzahl);
    cout&lt;&lt; endl;
    cout&lt;&lt; &quot;Der Gesamtwert betraegt: &quot; &lt;&lt; temp &lt;&lt;endl;
    cout&lt;&lt; &quot;Der Mittelwert betraegt: &quot; &lt;&lt; mittelwert &lt;&lt;endl;
    cout&lt;&lt; endl;
</code></pre>
<p>jetzt bekomm ich immer integerwerte raus.<br />
Was habe ich falsch gemacht? Es sollte eigentlich ein double-Wert sein!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1210570</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1210570</guid><dc:creator><![CDATA[testor]]></dc:creator><pubDate>Tue, 16 Jan 2007 09:34:28 GMT</pubDate></item><item><title><![CDATA[Reply to zufallszahlen &#x2F; ausgabe als double on Tue, 16 Jan 2007 09:59:06 GMT]]></title><description><![CDATA[<p>Du rechnest ja auch nur mit int-Werten, was erwartest du also? (solange keine double-Werte beteiligt sind, rechnet C++ mit integer-Arithmetik)</p>
<p>Als Lösung könntest du entweder die Variable 'temp' als double anlegen oder bei der Rechnung in einen double-Wert casten ( <code>double mittelwert = (double)temp / anzahl;</code> ).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1210582</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1210582</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Tue, 16 Jan 2007 09:59:06 GMT</pubDate></item><item><title><![CDATA[Reply to zufallszahlen &#x2F; ausgabe als double on Tue, 16 Jan 2007 15:57:13 GMT]]></title><description><![CDATA[<p>Pfui, ein C-Style Case, pfui Spinne! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<p>Schöner:</p>
<pre><code class="language-cpp">double mittelwert = double(temp) / anzahl;
// oder
double mittelwert = static_cast&lt;double&gt;(temp) / anzahl;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1210865</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1210865</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Tue, 16 Jan 2007 15:57:13 GMT</pubDate></item></channel></rss>