<?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[Random Funktion in einer Switch case Anweißung]]></title><description><![CDATA[<p>Ich habe versucht ein kleines Schere Stein Papier Spiel zu programmieren.<br />
Wenn man eine Zahl eingibt 1 2 oder 3 soll er eine beliebige Zahl ausgeben:<br />
Aber er bringt immer einen Error bei dieser Zeile wenn ich es compilieren lassen will<br />
srand(static_cast&lt;unsigned&gt;(time(0)));<br />
Kann man so die Random Fuktion überhaupt in eine switch case Anweißung reinschreiben.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;stdlib.h&gt;
#include &lt;conio.h&gt;
#include &lt;cstdlib&gt;
#include &lt;ctime&gt;
using namespace std;

int main()
{
    char Auswahl;
    int max;
    int min;

do
{

    cout&lt;&lt;&quot;\nSchere - Stein - Papier - Das Spiel&quot;&lt;&lt;endl;
    cout&lt;&lt;&quot;\nWaehle: \n(1)Schere\n(2)Stein\n(3)Papier \n(4)Beenden&quot;&lt;&lt;endl;
    cout&lt;&lt;&quot;\nEingabe:&quot;;
    cin&gt;&gt;Auswahl;

     switch(Auswahl)
    {

        case('1'):
        srand(std::time(0));
        cout&lt;&lt;rand()%3+1&lt;&lt;endl;
        break;

        case('2'):
        srand(std::time(0));
        cout&lt;&lt;rand()%3+1&lt;&lt;endl;
        break;

        case('3'):
        srand(std::time(0));
        cout&lt;&lt;rand()%3+1&lt;&lt;endl;
        break;

        case('4'):
        cout&lt;&lt;&quot;Das Spiel wird beendet...&quot;&lt;&lt;endl;
        break;

       default:
       cout&lt;&lt;&quot;Keine korrekte Eingabe.&quot;&lt;&lt;endl;
       break;

    }
    getch();
    system(&quot;cls&quot;);

}

while(Auswahl!='4');

    return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/289524/random-funktion-in-einer-switch-case-anweißung</link><generator>RSS for Node</generator><lastBuildDate>Wed, 19 Aug 2026 02:53:17 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/289524.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 06 Jul 2011 19:13:17 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Random Funktion in einer Switch case Anweißung on Thu, 07 Jul 2011 16:28:49 GMT]]></title><description><![CDATA[<p>Ich habe versucht ein kleines Schere Stein Papier Spiel zu programmieren.<br />
Wenn man eine Zahl eingibt 1 2 oder 3 soll er eine beliebige Zahl ausgeben:<br />
Aber er bringt immer einen Error bei dieser Zeile wenn ich es compilieren lassen will<br />
srand(static_cast&lt;unsigned&gt;(time(0)));<br />
Kann man so die Random Fuktion überhaupt in eine switch case Anweißung reinschreiben.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;stdlib.h&gt;
#include &lt;conio.h&gt;
#include &lt;cstdlib&gt;
#include &lt;ctime&gt;
using namespace std;

int main()
{
    char Auswahl;
    int max;
    int min;

do
{

    cout&lt;&lt;&quot;\nSchere - Stein - Papier - Das Spiel&quot;&lt;&lt;endl;
    cout&lt;&lt;&quot;\nWaehle: \n(1)Schere\n(2)Stein\n(3)Papier \n(4)Beenden&quot;&lt;&lt;endl;
    cout&lt;&lt;&quot;\nEingabe:&quot;;
    cin&gt;&gt;Auswahl;

     switch(Auswahl)
    {

        case('1'):
        srand(std::time(0));
        cout&lt;&lt;rand()%3+1&lt;&lt;endl;
        break;

        case('2'):
        srand(std::time(0));
        cout&lt;&lt;rand()%3+1&lt;&lt;endl;
        break;

        case('3'):
        srand(std::time(0));
        cout&lt;&lt;rand()%3+1&lt;&lt;endl;
        break;

        case('4'):
        cout&lt;&lt;&quot;Das Spiel wird beendet...&quot;&lt;&lt;endl;
        break;

       default:
       cout&lt;&lt;&quot;Keine korrekte Eingabe.&quot;&lt;&lt;endl;
       break;

    }
    getch();
    system(&quot;cls&quot;);

}

while(Auswahl!='4');

    return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2089681</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2089681</guid><dc:creator><![CDATA[tomcolaa]]></dc:creator><pubDate>Thu, 07 Jul 2011 16:28:49 GMT</pubDate></item><item><title><![CDATA[Reply to Random Funktion in einer Switch case Anweißung on Wed, 06 Jul 2011 19:21:20 GMT]]></title><description><![CDATA[<p>Da du die Fehlermeldung des Compilers nicht geschrieben hast, gehe ich einmal davon aus, dass ein</p>
<pre><code class="language-cpp">#include &lt;ctime&gt;
</code></pre>
<p>fehlt.<br />
Außerdem ist der Cast nicht notwendig:</p>
<pre><code class="language-cpp">srand(std::time(0));
</code></pre>
<p>Btw: Die Initialisierung ist eigentlich nur einmalig nötig.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2089683</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2089683</guid><dc:creator><![CDATA[yahendrik]]></dc:creator><pubDate>Wed, 06 Jul 2011 19:21:20 GMT</pubDate></item><item><title><![CDATA[Reply to Random Funktion in einer Switch case Anweißung on Wed, 06 Jul 2011 19:21:29 GMT]]></title><description><![CDATA[<p>Erstens: Es wäre noch hilfreich, wenn du die Fehlermeldung mit dazuschreibst.<br />
Zweitens: Entscheide dich bitte, ob du C-Header (stdio.h) oder C++-Header (cstdlib) verwenden willst - Headernamen wie cstdlib. dürften generell falsch sein.<br />
Drittens: srand() mußt du nicht vor jeder Zufallsziehnung aufrufen, sondern nur einmal am Programmstart.<br />
Viertens: sfds</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2089684</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2089684</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Wed, 06 Jul 2011 19:21:29 GMT</pubDate></item><item><title><![CDATA[Reply to Random Funktion in einer Switch case Anweißung on Wed, 06 Jul 2011 19:52:43 GMT]]></title><description><![CDATA[<p>Hier liegt der Hund begraben:</p>
<pre><code class="language-cpp">#include &lt;cstdlib.&gt;
</code></pre>
<p>Siehst du den Punkt?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2089700</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2089700</guid><dc:creator><![CDATA[Der Klusi]]></dc:creator><pubDate>Wed, 06 Jul 2011 19:52:43 GMT</pubDate></item><item><title><![CDATA[Reply to Random Funktion in einer Switch case Anweißung on Wed, 06 Jul 2011 19:53:39 GMT]]></title><description><![CDATA[<p>Das gleiche beim iostream.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2089701</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2089701</guid><dc:creator><![CDATA[Der Klusi]]></dc:creator><pubDate>Wed, 06 Jul 2011 19:53:39 GMT</pubDate></item><item><title><![CDATA[Reply to Random Funktion in einer Switch case Anweißung on Thu, 07 Jul 2011 14:39:47 GMT]]></title><description><![CDATA[<p>Sry ich bin erst seit gestern angemeldet und weiß noch nicht so viel.<br />
Vielen Dank für die vielen Antworten.<br />
Jetzt kommt auch keine Fehlermeldung mehr leider funktioniert aber nicht alles so.<br />
Ich hab mehrmals versucht die Initialisirung umzuschreiben und umzusetzen aber er gibt immernoch bei jeder Eingabe die 3 aus und keine zufällige Zahl könntet ihr mir noch ein paar Tipps geben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2089973</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2089973</guid><dc:creator><![CDATA[tomcolaa]]></dc:creator><pubDate>Thu, 07 Jul 2011 14:39:47 GMT</pubDate></item><item><title><![CDATA[Reply to Random Funktion in einer Switch case Anweißung on Thu, 07 Jul 2011 15:50:00 GMT]]></title><description><![CDATA[<p>Zeig doch mal, wie dein Code inzwischen aussieht.</p>
<p>Korrektur: Ist mir beim ersten durchsehen nicht sofort aufgefallen, aber der Ausdruck <code>rand()%1+3</code> ist nicht besonders sinnvoll - du berechnest den Rest der Zufallszahl bezüglich 1 (ist bei ganzen Zahlen immer 0) und addierst darauf einen festen Wert. Ich vermute mal, du wolltest eigentlich <code>rand()%3+1</code> schreiben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2090001</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2090001</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Thu, 07 Jul 2011 15:50:00 GMT</pubDate></item><item><title><![CDATA[Reply to Random Funktion in einer Switch case Anweißung on Thu, 07 Jul 2011 16:30:51 GMT]]></title><description><![CDATA[<p>Ok vielen Dank daran lag es.<br />
Aufjeden fall funktioniert es jetzt so wie es oben steht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2090014</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2090014</guid><dc:creator><![CDATA[tomcolaa]]></dc:creator><pubDate>Thu, 07 Jul 2011 16:30:51 GMT</pubDate></item></channel></rss>