<?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[Aufruf von Funktion, Variablenübergabe]]></title><description><![CDATA[<p>Ich habe ein Programm geschrieben das Zufallszahlen zwischen 1 und 0 erzeugt. Jetzt stelle ich aber fest, dass meine Variablenübergabe nicht richtig funktioniert. Wo liegt der Fehler?</p>
<pre><code class="language-cpp">#include &lt;cstdio&gt;
#include &lt;cstdlib&gt;
#include &lt;time.h&gt;
#include &lt;iostream&gt;

using namespace std;

//zufälliges Ereignis
void Zufallszahlen(double ZufallsZ)
{

srand ((unsigned) time (NULL));    
ZufallsZ=(rand() / (double)RAND_MAX);

cout&lt;&lt; ZufallsZ &lt;&lt; endl;
}

//Hauptprogramm
int main()
{

double ZufallsZ;

Zufallszahlen(ZufallsZ);

cout&lt;&lt; ZufallsZ;
system(&quot;PAUSE&quot;);
return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/162931/aufruf-von-funktion-variablenübergabe</link><generator>RSS for Node</generator><lastBuildDate>Sat, 12 Sep 2026 20:00:23 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/162931.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 24 Oct 2006 14:10:18 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Aufruf von Funktion, Variablenübergabe on Tue, 24 Oct 2006 14:10:18 GMT]]></title><description><![CDATA[<p>Ich habe ein Programm geschrieben das Zufallszahlen zwischen 1 und 0 erzeugt. Jetzt stelle ich aber fest, dass meine Variablenübergabe nicht richtig funktioniert. Wo liegt der Fehler?</p>
<pre><code class="language-cpp">#include &lt;cstdio&gt;
#include &lt;cstdlib&gt;
#include &lt;time.h&gt;
#include &lt;iostream&gt;

using namespace std;

//zufälliges Ereignis
void Zufallszahlen(double ZufallsZ)
{

srand ((unsigned) time (NULL));    
ZufallsZ=(rand() / (double)RAND_MAX);

cout&lt;&lt; ZufallsZ &lt;&lt; endl;
}

//Hauptprogramm
int main()
{

double ZufallsZ;

Zufallszahlen(ZufallsZ);

cout&lt;&lt; ZufallsZ;
system(&quot;PAUSE&quot;);
return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1160352</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1160352</guid><dc:creator><![CDATA[becks21]]></dc:creator><pubDate>Tue, 24 Oct 2006 14:10:18 GMT</pubDate></item><item><title><![CDATA[Reply to Aufruf von Funktion, Variablenübergabe on Tue, 24 Oct 2006 14:18:07 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>Was bedeutet denn: &quot;nicht richtig klappt&quot;?</p>
<p>Wenn Du Variablen direkt übergibst, wird immer eine Kopie gemacht und das Original wird nicht verändert. Wenn du das willst, musst du die Variable entweder als Referenz oder als Zeiger übergeben.</p>
<p>chrische</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1160363</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1160363</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Tue, 24 Oct 2006 14:18:07 GMT</pubDate></item><item><title><![CDATA[Reply to Aufruf von Funktion, Variablenübergabe on Tue, 24 Oct 2006 14:21:52 GMT]]></title><description><![CDATA[<p>Es wäre eh sinnvoller gleich ein double zurückzugeben.</p>
<p>Außerdem solltest du srand() nur einmal pro Programm ausführen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1160365</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1160365</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Tue, 24 Oct 2006 14:21:52 GMT</pubDate></item><item><title><![CDATA[Reply to Aufruf von Funktion, Variablenübergabe on Tue, 24 Oct 2006 14:24:26 GMT]]></title><description><![CDATA[<p>Verwende nicht</p>
<pre><code class="language-cpp">void Zufallszahlen(double ZufallsZ)
</code></pre>
<p>sondern</p>
<pre><code class="language-cpp">void Zufallszahlen(double&amp; ZufallsZ)
</code></pre>
<p>Damit verwendest du eine Referenz auf den Wert, musst aber nicht (wie bei Zeigern) eine Adresse übergeben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1160370</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1160370</guid><dc:creator><![CDATA[Sid2K6]]></dc:creator><pubDate>Tue, 24 Oct 2006 14:24:26 GMT</pubDate></item><item><title><![CDATA[Reply to Aufruf von Funktion, Variablenübergabe on Tue, 24 Oct 2006 14:24:30 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>TactX schrieb:</p>
<blockquote>
<p>Außerdem solltest du srand() nur einmal pro Programm ausführen.</p>
</blockquote>
<p>Er führt es doch aber bloss einmal aus.</p>
<p>chrische</p>
<p>P.S.: ctime statt time.h</p>
<p>chrische</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1160371</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1160371</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Tue, 24 Oct 2006 14:24:30 GMT</pubDate></item><item><title><![CDATA[Reply to Aufruf von Funktion, Variablenübergabe on Tue, 24 Oct 2006 14:26:59 GMT]]></title><description><![CDATA[<p>chrische5 schrieb:</p>
<blockquote>
<p>Hallo</p>
<p>TactX schrieb:</p>
<blockquote>
<p>Außerdem solltest du srand() nur einmal pro Programm ausführen.</p>
</blockquote>
<p>Er führt es doch aber bloss einmal aus.</p>
</blockquote>
<p>wenn man davon ausgeht, dass er nur eine einzige zufallszahl benötigt schon..<br />
<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/1160372</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1160372</guid><dc:creator><![CDATA[Cpt. Tanga]]></dc:creator><pubDate>Tue, 24 Oct 2006 14:26:59 GMT</pubDate></item><item><title><![CDATA[Reply to Aufruf von Funktion, Variablenübergabe on Tue, 24 Oct 2006 14:27:21 GMT]]></title><description><![CDATA[<p>chrische5 schrieb:</p>
<blockquote>
<p>Hallo</p>
<p>Er führt es doch aber bloss einmal aus.</p>
</blockquote>
<p>sie <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>
]]></description><link>https://www.c-plusplus.net/forum/post/1160374</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1160374</guid><dc:creator><![CDATA[becks21]]></dc:creator><pubDate>Tue, 24 Oct 2006 14:27:21 GMT</pubDate></item><item><title><![CDATA[Reply to Aufruf von Funktion, Variablenübergabe on Tue, 24 Oct 2006 14:28:18 GMT]]></title><description><![CDATA[<p>Cpt. Tanga schrieb:</p>
<blockquote>
<p>chrische5 schrieb:</p>
<blockquote>
<p>Hallo</p>
<p>TactX schrieb:</p>
<blockquote>
<p>Außerdem solltest du srand() nur einmal pro Programm ausführen.</p>
</blockquote>
<p>Er führt es doch aber bloss einmal aus.</p>
</blockquote>
<p>wenn man davon ausgeht, dass er nur eine einzige zufallszahl benötigt schon..<br />
<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>Dann einfach im Hauptprogramm einmal aufrufen? Geht das?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1160376</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1160376</guid><dc:creator><![CDATA[becks21]]></dc:creator><pubDate>Tue, 24 Oct 2006 14:28:18 GMT</pubDate></item><item><title><![CDATA[Reply to Aufruf von Funktion, Variablenübergabe on Tue, 24 Oct 2006 14:29:24 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>Cpt. Tanga schrieb:</p>
<blockquote>
<p>chrische5 schrieb:</p>
<blockquote>
<p>Hallo</p>
<p>TactX schrieb:</p>
<blockquote>
<p>Außerdem solltest du srand() nur einmal pro Programm ausführen.</p>
</blockquote>
<p>Er führt es doch aber bloss einmal aus.</p>
</blockquote>
<p>wenn man davon ausgeht, dass er nur eine einzige zufallszahl benötigt schon..<br />
<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>War ja auch nicht ganz ernst gemeint.</p>
<p>chrische</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1160380</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1160380</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Tue, 24 Oct 2006 14:29:24 GMT</pubDate></item><item><title><![CDATA[Reply to Aufruf von Funktion, Variablenübergabe on Tue, 24 Oct 2006 14:31:39 GMT]]></title><description><![CDATA[<p>becks21 schrieb:</p>
<blockquote>
<p>Cpt. Tanga schrieb:</p>
<blockquote>
<p>chrische5 schrieb:</p>
<blockquote>
<p>Hallo</p>
<p>TactX schrieb:</p>
<blockquote>
<p>Außerdem solltest du srand() nur einmal pro Programm ausführen.</p>
</blockquote>
<p>Er führt es doch aber bloss einmal aus.</p>
</blockquote>
<p>wenn man davon ausgeht, dass er nur eine einzige zufallszahl benötigt schon..<br />
<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>Dann einfach im Hauptprogramm einmal aufrufen? Geht das?</p>
</blockquote>
<p>Genau.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1160382</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1160382</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Tue, 24 Oct 2006 14:31:39 GMT</pubDate></item><item><title><![CDATA[Reply to Aufruf von Funktion, Variablenübergabe on Tue, 24 Oct 2006 14:41:18 GMT]]></title><description><![CDATA[<p>Gut, danke.</p>
<p>Und was ist der Unterschied zwischen ctime und time.h?</p>
<p>Ich weiß, ich frage ganz schön blöd, aber ich habe gerade erst angefangen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1160389</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1160389</guid><dc:creator><![CDATA[becks21]]></dc:creator><pubDate>Tue, 24 Oct 2006 14:41:18 GMT</pubDate></item><item><title><![CDATA[Reply to Aufruf von Funktion, Variablenübergabe on Tue, 24 Oct 2006 14:44:24 GMT]]></title><description><![CDATA[<p>ctime ist ISO-C++ Standard, time.h nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1160398</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1160398</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Tue, 24 Oct 2006 14:44:24 GMT</pubDate></item></channel></rss>