<?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[&amp;quot;Routine&amp;quot; für Variablen?]]></title><description><![CDATA[<p>Hallo!</p>
<p>Ich habe folgendes Programm geschrieben:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;windows.h&gt;
#include &lt;ctime&gt;

using namespace std;

int main()
{
    srand((unsigned)time(0));
    /*Variablen deklarieren--&gt;*/
    short choice1 = 0;
    short start = 0;
    double ende = 0;
    double c1Muenze = 0;
    double c2Muenze = 0;
    double c1Wuerfel = 0;
    double c2Wuerfel = 0;
    double c3Wuerfel = 0;
    double c4Wuerfel = 0;
    double c5Wuerfel = 0;
    double c6Wuerfel = 0;
    /*&lt;--Variablen deklarieren*/
    /*Titel festlegen und Informationen anzeigen--&gt;*/
    SetConsoleTitle(&quot;W'keits Simulator&quot;);
    cout &lt;&lt; &quot;&lt;&lt;Dieses Programm simuliert Wahrscheinlichkeiten in verschiedenen Situationen&gt;&gt;\n&quot; &lt;&lt; endl;
    /*&lt;--Titel festlegen und Informationen anzeigen*/
    while (1)
    {
        /*Variablen auf 0 zurücksetzten--&gt;*/
        c1Muenze = 0;
        c2Muenze = 0;
        c1Wuerfel = 0;
        c2Wuerfel = 0;
        c3Wuerfel = 0;
        c4Wuerfel = 0;
        c5Wuerfel = 0;
        c6Wuerfel = 0;
        ende = 0;
        /*&lt;--Variablen auf 0 zurücksetzten*/
        /*Auflisten der Möglichkeiten--&gt;*/
        cout &lt;&lt; &quot;Sie koennen...\n&quot;;
        cout &lt;&lt; &quot;1 - Eine M\x81nze simulieren...&quot; &lt;&lt; endl;
        cout &lt;&lt; &quot;2 - Einen W\x81rfel simulieren...&quot; &lt;&lt; endl;
        cout &lt;&lt; &quot;Geben sie die Ziffer des gew\x81nschten Vorganges ein: &quot;;
        cin &gt;&gt; choice1;
        /*&lt;--*/
        /*Abfragen der Eingabe für choice1*/
        /*Die Münze wurde gewählt--&gt;*/
        if (choice1 == 1) {
            cout &lt;&lt; &quot;\nSie moechten eine M\x81nze simulieren...\n&quot; &lt;&lt; endl;
            cout &lt;&lt; &quot;Wie oft soll geworfen werden?: &quot;;
            cin &gt;&gt; ende;
            cout &lt;&lt; &quot;\nEs wird &quot; &lt;&lt; ende &lt;&lt; &quot;mal geworfen in 3...&quot;;
            Sleep(1000);
            cout &lt;&lt; &quot;2...&quot;;
            Sleep(1000);
            cout &lt;&lt; &quot;1\n\n&quot;;
            Sleep(1000);
            for (start = 0; start &lt; ende; start++) {
                short zMuenze = rand() % 2 + 1;
                Sleep(10);
                if (zMuenze == 1)
                {
                    cout &lt;&lt; &quot;Kopf&quot; &lt;&lt; endl;
                    c1Muenze += 1;
                }
                if (zMuenze == 2)
                {
                    cout &lt;&lt; &quot;Zahl&quot; &lt;&lt; endl;
                    c2Muenze += 1;
                }
            }
            if (start == ende) {
                cout &lt;&lt; &quot;Die M\x81nze wurde &quot; &lt;&lt; ende &lt;&lt; &quot;mal geworfen.&quot; &lt;&lt; endl;
                cout &lt;&lt; &quot;Ergebnis: &quot; &lt;&lt; endl;
                cout &lt;&lt; &quot;Anzahl Kopf: &quot; &lt;&lt; c1Muenze &lt;&lt; endl;
                cout &lt;&lt; &quot;Anzahl Zahl: &quot; &lt;&lt; c2Muenze &lt;&lt; &quot;\n\n&quot; &lt;&lt; endl;
            }
        }
        /*&lt;--Die Münze wurde gewählt*/
        /*Der Würfel wurde gewählt--&gt;*/
        if (choice1 == 2) {
            cout &lt;&lt; &quot;\Sie moechten einen W\x81rfel simulieren...\n&quot; &lt;&lt; endl;
            cout &lt;&lt; &quot;Wie oft soll gew\x81rfelt werden?: &quot;;
            cin &gt;&gt; ende;
            cout &lt;&lt; &quot;Es wird &quot; &lt;&lt; ende &lt;&lt; &quot;mal gew\x81rfelt in 3...&quot;;
            Sleep(1000);
            cout &lt;&lt; &quot;2...&quot;;
            Sleep(1000);
            cout &lt;&lt; &quot;1\n&quot;;
            Sleep(1000);
            for (start = 0; start &lt; ende; start++) {
                short zWuerfel = rand() % 6 + 1;
                Sleep(10);
                cout &lt;&lt; zWuerfel &lt;&lt; endl;
                if (zWuerfel == 1)
                {
                    c1Wuerfel += 1;
                }
                if (zWuerfel == 2)
                {
                    c2Wuerfel += 1;
                }
                if (zWuerfel == 3)
                {
                    c3Wuerfel += 1;
                }
                if (zWuerfel == 4)
                {
                    c4Wuerfel += 1;
                }
                if (zWuerfel == 5)
                {
                    c5Wuerfel += 1;
                }
                if (zWuerfel == 6)
                {
                    c6Wuerfel += 1;
                }
            }
            if (start == ende) {
                cout &lt;&lt; &quot;Es wurde &quot; &lt;&lt; ende &lt;&lt; &quot;mal gew\x81rfelt.&quot; &lt;&lt; endl;
                Sleep(800);
                cout &lt;&lt; &quot;Ergebnis: &quot; &lt;&lt; endl;
                cout &lt;&lt; &quot;Anzahl 1: &quot; &lt;&lt; c1Wuerfel &lt;&lt; endl;
                cout &lt;&lt; &quot;Anzahl 2: &quot; &lt;&lt; c2Wuerfel &lt;&lt; endl;
                cout &lt;&lt; &quot;Anzahl 3: &quot; &lt;&lt; c3Wuerfel &lt;&lt; endl;
                cout &lt;&lt; &quot;Anzahl 4: &quot; &lt;&lt; c4Wuerfel &lt;&lt; endl;
                cout &lt;&lt; &quot;Anzahl 5: &quot; &lt;&lt; c5Wuerfel &lt;&lt; endl;
                cout &lt;&lt; &quot;Anzahl 6: &quot; &lt;&lt; c6Wuerfel &lt;&lt; &quot;\n\n&quot; &lt;&lt; endl;
            }
        }
        /*&lt;--Der Würfel wurde gewählt*/
    }
    /*&lt;--Abfragen der Eingabe für choice1*/
    return 0;
}
</code></pre>
<p>Nun möchte ich noch eine Funktion &quot;Lottozahlen&quot; einfügen.<br />
Dabei soll der User aber einstellen können, WIEVIELE Kugeln(Zahlen) es gibt.<br />
Bei &quot;Münze&quot; und &quot;Würfel&quot; kann ich ja von Anfang an sagen, dass es 2 bzw. 6 Möglichkeiten gibt, das geht aber mit den &quot;Lottozahlen&quot; nicht.<br />
Dazu bräuchte ich jetzt so eine Art &quot;Routine&quot;, die für JEDE Zahl, die zwischen<br />
1 und der Usereingabe vorkommt ein Variable erstellt, bei der dann immer, wenn diese nocheinmal vorkommt z.B.</p>
<pre><code class="language-cpp">253 += 1;
</code></pre>
<p>rechnet.</p>
<p>Ich denke mal, soetwas sollte möglich sein, aber wie bekomme ich das hin?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/267328/quot-routine-quot-für-variablen</link><generator>RSS for Node</generator><lastBuildDate>Wed, 02 Sep 2026 14:26:38 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/267328.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 22 May 2010 16:14:12 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to &amp;quot;Routine&amp;quot; für Variablen? on Sat, 22 May 2010 16:14:45 GMT]]></title><description><![CDATA[<p>Hallo!</p>
<p>Ich habe folgendes Programm geschrieben:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;windows.h&gt;
#include &lt;ctime&gt;

using namespace std;

int main()
{
    srand((unsigned)time(0));
    /*Variablen deklarieren--&gt;*/
    short choice1 = 0;
    short start = 0;
    double ende = 0;
    double c1Muenze = 0;
    double c2Muenze = 0;
    double c1Wuerfel = 0;
    double c2Wuerfel = 0;
    double c3Wuerfel = 0;
    double c4Wuerfel = 0;
    double c5Wuerfel = 0;
    double c6Wuerfel = 0;
    /*&lt;--Variablen deklarieren*/
    /*Titel festlegen und Informationen anzeigen--&gt;*/
    SetConsoleTitle(&quot;W'keits Simulator&quot;);
    cout &lt;&lt; &quot;&lt;&lt;Dieses Programm simuliert Wahrscheinlichkeiten in verschiedenen Situationen&gt;&gt;\n&quot; &lt;&lt; endl;
    /*&lt;--Titel festlegen und Informationen anzeigen*/
    while (1)
    {
        /*Variablen auf 0 zurücksetzten--&gt;*/
        c1Muenze = 0;
        c2Muenze = 0;
        c1Wuerfel = 0;
        c2Wuerfel = 0;
        c3Wuerfel = 0;
        c4Wuerfel = 0;
        c5Wuerfel = 0;
        c6Wuerfel = 0;
        ende = 0;
        /*&lt;--Variablen auf 0 zurücksetzten*/
        /*Auflisten der Möglichkeiten--&gt;*/
        cout &lt;&lt; &quot;Sie koennen...\n&quot;;
        cout &lt;&lt; &quot;1 - Eine M\x81nze simulieren...&quot; &lt;&lt; endl;
        cout &lt;&lt; &quot;2 - Einen W\x81rfel simulieren...&quot; &lt;&lt; endl;
        cout &lt;&lt; &quot;Geben sie die Ziffer des gew\x81nschten Vorganges ein: &quot;;
        cin &gt;&gt; choice1;
        /*&lt;--*/
        /*Abfragen der Eingabe für choice1*/
        /*Die Münze wurde gewählt--&gt;*/
        if (choice1 == 1) {
            cout &lt;&lt; &quot;\nSie moechten eine M\x81nze simulieren...\n&quot; &lt;&lt; endl;
            cout &lt;&lt; &quot;Wie oft soll geworfen werden?: &quot;;
            cin &gt;&gt; ende;
            cout &lt;&lt; &quot;\nEs wird &quot; &lt;&lt; ende &lt;&lt; &quot;mal geworfen in 3...&quot;;
            Sleep(1000);
            cout &lt;&lt; &quot;2...&quot;;
            Sleep(1000);
            cout &lt;&lt; &quot;1\n\n&quot;;
            Sleep(1000);
            for (start = 0; start &lt; ende; start++) {
                short zMuenze = rand() % 2 + 1;
                Sleep(10);
                if (zMuenze == 1)
                {
                    cout &lt;&lt; &quot;Kopf&quot; &lt;&lt; endl;
                    c1Muenze += 1;
                }
                if (zMuenze == 2)
                {
                    cout &lt;&lt; &quot;Zahl&quot; &lt;&lt; endl;
                    c2Muenze += 1;
                }
            }
            if (start == ende) {
                cout &lt;&lt; &quot;Die M\x81nze wurde &quot; &lt;&lt; ende &lt;&lt; &quot;mal geworfen.&quot; &lt;&lt; endl;
                cout &lt;&lt; &quot;Ergebnis: &quot; &lt;&lt; endl;
                cout &lt;&lt; &quot;Anzahl Kopf: &quot; &lt;&lt; c1Muenze &lt;&lt; endl;
                cout &lt;&lt; &quot;Anzahl Zahl: &quot; &lt;&lt; c2Muenze &lt;&lt; &quot;\n\n&quot; &lt;&lt; endl;
            }
        }
        /*&lt;--Die Münze wurde gewählt*/
        /*Der Würfel wurde gewählt--&gt;*/
        if (choice1 == 2) {
            cout &lt;&lt; &quot;\Sie moechten einen W\x81rfel simulieren...\n&quot; &lt;&lt; endl;
            cout &lt;&lt; &quot;Wie oft soll gew\x81rfelt werden?: &quot;;
            cin &gt;&gt; ende;
            cout &lt;&lt; &quot;Es wird &quot; &lt;&lt; ende &lt;&lt; &quot;mal gew\x81rfelt in 3...&quot;;
            Sleep(1000);
            cout &lt;&lt; &quot;2...&quot;;
            Sleep(1000);
            cout &lt;&lt; &quot;1\n&quot;;
            Sleep(1000);
            for (start = 0; start &lt; ende; start++) {
                short zWuerfel = rand() % 6 + 1;
                Sleep(10);
                cout &lt;&lt; zWuerfel &lt;&lt; endl;
                if (zWuerfel == 1)
                {
                    c1Wuerfel += 1;
                }
                if (zWuerfel == 2)
                {
                    c2Wuerfel += 1;
                }
                if (zWuerfel == 3)
                {
                    c3Wuerfel += 1;
                }
                if (zWuerfel == 4)
                {
                    c4Wuerfel += 1;
                }
                if (zWuerfel == 5)
                {
                    c5Wuerfel += 1;
                }
                if (zWuerfel == 6)
                {
                    c6Wuerfel += 1;
                }
            }
            if (start == ende) {
                cout &lt;&lt; &quot;Es wurde &quot; &lt;&lt; ende &lt;&lt; &quot;mal gew\x81rfelt.&quot; &lt;&lt; endl;
                Sleep(800);
                cout &lt;&lt; &quot;Ergebnis: &quot; &lt;&lt; endl;
                cout &lt;&lt; &quot;Anzahl 1: &quot; &lt;&lt; c1Wuerfel &lt;&lt; endl;
                cout &lt;&lt; &quot;Anzahl 2: &quot; &lt;&lt; c2Wuerfel &lt;&lt; endl;
                cout &lt;&lt; &quot;Anzahl 3: &quot; &lt;&lt; c3Wuerfel &lt;&lt; endl;
                cout &lt;&lt; &quot;Anzahl 4: &quot; &lt;&lt; c4Wuerfel &lt;&lt; endl;
                cout &lt;&lt; &quot;Anzahl 5: &quot; &lt;&lt; c5Wuerfel &lt;&lt; endl;
                cout &lt;&lt; &quot;Anzahl 6: &quot; &lt;&lt; c6Wuerfel &lt;&lt; &quot;\n\n&quot; &lt;&lt; endl;
            }
        }
        /*&lt;--Der Würfel wurde gewählt*/
    }
    /*&lt;--Abfragen der Eingabe für choice1*/
    return 0;
}
</code></pre>
<p>Nun möchte ich noch eine Funktion &quot;Lottozahlen&quot; einfügen.<br />
Dabei soll der User aber einstellen können, WIEVIELE Kugeln(Zahlen) es gibt.<br />
Bei &quot;Münze&quot; und &quot;Würfel&quot; kann ich ja von Anfang an sagen, dass es 2 bzw. 6 Möglichkeiten gibt, das geht aber mit den &quot;Lottozahlen&quot; nicht.<br />
Dazu bräuchte ich jetzt so eine Art &quot;Routine&quot;, die für JEDE Zahl, die zwischen<br />
1 und der Usereingabe vorkommt ein Variable erstellt, bei der dann immer, wenn diese nocheinmal vorkommt z.B.</p>
<pre><code class="language-cpp">253 += 1;
</code></pre>
<p>rechnet.</p>
<p>Ich denke mal, soetwas sollte möglich sein, aber wie bekomme ich das hin?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1901208</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1901208</guid><dc:creator><![CDATA[R3DL10N]]></dc:creator><pubDate>Sat, 22 May 2010 16:14:45 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;quot;Routine&amp;quot; für Variablen? on Sat, 22 May 2010 16:27:10 GMT]]></title><description><![CDATA[<p>Das hättest du bereits von Anfang an tun sollen, selbst für die 6 Würfel:</p>
<pre><code class="language-cpp">#include &lt;vector&gt;

...

vector&lt;int&gt; nums; // verstehe nicht wieso du double als typ verwendest...

...

nums.push_back(some_number); // einen mehr dranfügen

...

for(int i = 0; i &lt; nums.size(); ++i) // bin mir nicht sicher in c++ das size() heißt
{
    int num = nums[i];
    // do sth with num
}

...

nums.clear(); // mach das wieder leer, keine zahlen mehr drin
</code></pre>
<p>Kann noch viel mehr als das hier...</p>
<p>MfG SideWinder</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1901211</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1901211</guid><dc:creator><![CDATA[SideWinder]]></dc:creator><pubDate>Sat, 22 May 2010 16:27:10 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;quot;Routine&amp;quot; für Variablen? on Sat, 22 May 2010 16:28:01 GMT]]></title><description><![CDATA[<p>Mit</p>
<pre><code class="language-cpp">#include&lt;vector&gt;

// ...

vector&lt;int&gt; viele_ints(N);
</code></pre>
<p>Kannst du N int-Variablen erstellen. Zugreifen kannst du auf diese mittels <code>viele_ints[0]</code> bis <code>viele_ints[N-1]</code> . Pass also unbedingt auf, dass die Zählung bei 0 beginnt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1901213</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1901213</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Sat, 22 May 2010 16:28:01 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;quot;Routine&amp;quot; für Variablen? on Sat, 22 May 2010 16:49:48 GMT]]></title><description><![CDATA[<p>Lottozahlen mit rand() sind aber etwas tricky, da ja jede Zahl nur einmal vorkommen soll. Du kannst das z.B. so lösen:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;vector&gt;
#include &lt;algorithm&gt;
#include &lt;ctime&gt;

typedef std::vector&lt;int&gt; IntVec;

IntVec ziehung(size_t ziehung, size_t gesamt);

int main()
{
	srand(static_cast&lt;unsigned int&gt;(time(NULL)));

	// 6 aus 49
	IntVec zahlen = ziehung(6, 49);

	for (IntVec::iterator it = zahlen.begin(); it != zahlen.end(); ++it)
	{
		std::cout &lt;&lt; *it &lt;&lt; std::endl;
	}

	return 0;
}

IntVec ziehung(size_t ziehung, size_t gesamt)
{
	IntVec zahlen;

	for (unsigned int i = 1; i &lt;= gesamt; ++i)
	{
		zahlen.push_back(i);
	}

	std::random_shuffle(zahlen.begin(), zahlen.end());
	zahlen.erase(zahlen.begin() + ziehung, zahlen.end());

	return zahlen;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1901218</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1901218</guid><dc:creator><![CDATA[ghjghj]]></dc:creator><pubDate>Sat, 22 May 2010 16:49:48 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;quot;Routine&amp;quot; für Variablen? on Sat, 22 May 2010 17:52:06 GMT]]></title><description><![CDATA[<p>Das blöde ist nur, ich kann ja jetzt mit</p>
<pre><code class="language-cpp">vector&lt;int&gt;LottoZahlen;
</code></pre>
<p>nicht mehr</p>
<pre><code class="language-cpp">cout &lt;&lt; &quot;Anzahl Eingeben: &quot;;
cin &gt;&gt; LottoZahlen;
</code></pre>
<p>verwenden...<br />
Bei mir wird dann immer ein Fehler ausgegeben...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1901227</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1901227</guid><dc:creator><![CDATA[R3DL10N]]></dc:creator><pubDate>Sat, 22 May 2010 17:52:06 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;quot;Routine&amp;quot; für Variablen? on Sat, 22 May 2010 20:58:17 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">int LottoZahlen;

cout &lt;&lt; &quot;Anzahl Eingeben: &quot;;
cin &gt;&gt; LottoZahlen; 

vector&lt;int&gt; zahlen(LottoZahlen);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1901271</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1901271</guid><dc:creator><![CDATA[.....]]></dc:creator><pubDate>Sat, 22 May 2010 20:58:17 GMT</pubDate></item></channel></rss>