<?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[switch case in eine Schleife setzen]]></title><description><![CDATA[<p>Moin Leute,<br />
bin ein blutiger Anfänger in C++ und wollte mir heute mal einen kleinen Taschenrechner basteln.<br />
Hat alles soweit funktioniert, aber ich möchte dass sich das Programm immer wiederholt bzw. neustartet.<br />
Das heißt ich gebe jetzt z.B bei der Addition 2+7 ein wird das Programm beendet, aber ich möchte danach noch eine andere Eingabe machen.<br />
Ich hab mir gedacht dass man dies in Form von einer Schleife machen kann.<br />
Also das dies solange wiederholt wird bis ich etwas eingebe wie z.B /q</p>
<p>Danke im Voraus, und hier ist der Code:</p>
<pre><code>#include &lt;iostream&gt;

using namespace std;

int main(void)
{
	cout &lt;&lt; &quot;Bitte waehle eine Rechenmethode aus\n1. Addition\n2. Subtraktion\n3. Multiplikation\n4. Division&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;Du kannst jeder Zeit /q schreiben um das Programm zu beenden.&quot; &lt;&lt; endl; 

	char auswahl;
	cin &gt;&gt; auswahl;

	switch( auswahl ) {
			case'1':
			cout &lt;&lt; &quot;Bitte waehle deine erste Zahl aus: &quot;;
			int zahl_1;
			cin &gt;&gt; zahl_1;
			cout &lt;&lt; &quot;Bitte waehle deine zweite Zahl aus: &quot;;
			int zahl_2;
			cin &gt;&gt; zahl_2;
			int ergebnis_add;
			ergebnis_add = zahl_1 + zahl_2;
			cout &lt;&lt; &quot;Das Ergebnis von &quot; &lt;&lt; zahl_1 &lt;&lt; &quot;+&quot; &lt;&lt; zahl_2 &lt;&lt; &quot; ist &quot; &lt;&lt; ergebnis_add &lt;&lt; endl;
			break;

			case'2':
			cout &lt;&lt; &quot;Bitte waehle deine erste Zahl aus: &quot;;
			float zahl_3;
			cin &gt;&gt; zahl_3;
			cout &lt;&lt; &quot;Bitte waehle deine zweite Zahl aus: &quot;;
			float zahl_4;
			cin &gt;&gt; zahl_4;
			float ergebnis_sub;
			ergebnis_sub = zahl_3 - zahl_4;
			cout &lt;&lt; &quot;Das Ergebnis von &quot; &lt;&lt; zahl_3 &lt;&lt; &quot;-&quot; &lt;&lt; zahl_4 &lt;&lt; &quot; ist &quot; &lt;&lt; ergebnis_sub &lt;&lt; endl;
			break;

			case'3':
			cout &lt;&lt; &quot;Bitte waehle deine erste Zahl aus: &quot;;
			float zahl_5;
			cin &gt;&gt; zahl_5;
			cout &lt;&lt; &quot;Bitte waehle deine zweite Zahl aus: &quot;;
			float zahl_6;
			cin &gt;&gt; zahl_6;
			float ergebnis_mul;
			ergebnis_mul = zahl_5 * zahl_6;
			cout &lt;&lt; &quot;Das Ergebnis von &quot; &lt;&lt; zahl_5 &lt;&lt; &quot;x&quot; &lt;&lt; zahl_6 &lt;&lt; &quot; ist &quot; &lt;&lt; ergebnis_mul &lt;&lt; endl;

			case'4':
			cout &lt;&lt; &quot;Bitte waehle deine erste Zahl aus: &quot;;
			float zahl_7;
			cin &gt;&gt; zahl_7;
			cout &lt;&lt; &quot;Bitte waehle deine zweite Zahl aus: &quot;;
			float zahl_8;
			cin &gt;&gt; zahl_8;
			float ergebnis_div;
			ergebnis_div = zahl_7 / zahl_8;
			cout &lt;&lt; &quot;Das Ergebnis von &quot; &lt;&lt; zahl_7 &lt;&lt; &quot;/&quot; &lt;&lt; zahl_8 &lt;&lt; &quot; ist &quot; &lt;&lt; ergebnis_div &lt;&lt; endl;	
	}

}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/324069/switch-case-in-eine-schleife-setzen</link><generator>RSS for Node</generator><lastBuildDate>Wed, 15 Jul 2026 02:13:01 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/324069.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 01 Mar 2014 19:45:26 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to switch case in eine Schleife setzen on Sat, 01 Mar 2014 19:45:26 GMT]]></title><description><![CDATA[<p>Moin Leute,<br />
bin ein blutiger Anfänger in C++ und wollte mir heute mal einen kleinen Taschenrechner basteln.<br />
Hat alles soweit funktioniert, aber ich möchte dass sich das Programm immer wiederholt bzw. neustartet.<br />
Das heißt ich gebe jetzt z.B bei der Addition 2+7 ein wird das Programm beendet, aber ich möchte danach noch eine andere Eingabe machen.<br />
Ich hab mir gedacht dass man dies in Form von einer Schleife machen kann.<br />
Also das dies solange wiederholt wird bis ich etwas eingebe wie z.B /q</p>
<p>Danke im Voraus, und hier ist der Code:</p>
<pre><code>#include &lt;iostream&gt;

using namespace std;

int main(void)
{
	cout &lt;&lt; &quot;Bitte waehle eine Rechenmethode aus\n1. Addition\n2. Subtraktion\n3. Multiplikation\n4. Division&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;Du kannst jeder Zeit /q schreiben um das Programm zu beenden.&quot; &lt;&lt; endl; 

	char auswahl;
	cin &gt;&gt; auswahl;

	switch( auswahl ) {
			case'1':
			cout &lt;&lt; &quot;Bitte waehle deine erste Zahl aus: &quot;;
			int zahl_1;
			cin &gt;&gt; zahl_1;
			cout &lt;&lt; &quot;Bitte waehle deine zweite Zahl aus: &quot;;
			int zahl_2;
			cin &gt;&gt; zahl_2;
			int ergebnis_add;
			ergebnis_add = zahl_1 + zahl_2;
			cout &lt;&lt; &quot;Das Ergebnis von &quot; &lt;&lt; zahl_1 &lt;&lt; &quot;+&quot; &lt;&lt; zahl_2 &lt;&lt; &quot; ist &quot; &lt;&lt; ergebnis_add &lt;&lt; endl;
			break;

			case'2':
			cout &lt;&lt; &quot;Bitte waehle deine erste Zahl aus: &quot;;
			float zahl_3;
			cin &gt;&gt; zahl_3;
			cout &lt;&lt; &quot;Bitte waehle deine zweite Zahl aus: &quot;;
			float zahl_4;
			cin &gt;&gt; zahl_4;
			float ergebnis_sub;
			ergebnis_sub = zahl_3 - zahl_4;
			cout &lt;&lt; &quot;Das Ergebnis von &quot; &lt;&lt; zahl_3 &lt;&lt; &quot;-&quot; &lt;&lt; zahl_4 &lt;&lt; &quot; ist &quot; &lt;&lt; ergebnis_sub &lt;&lt; endl;
			break;

			case'3':
			cout &lt;&lt; &quot;Bitte waehle deine erste Zahl aus: &quot;;
			float zahl_5;
			cin &gt;&gt; zahl_5;
			cout &lt;&lt; &quot;Bitte waehle deine zweite Zahl aus: &quot;;
			float zahl_6;
			cin &gt;&gt; zahl_6;
			float ergebnis_mul;
			ergebnis_mul = zahl_5 * zahl_6;
			cout &lt;&lt; &quot;Das Ergebnis von &quot; &lt;&lt; zahl_5 &lt;&lt; &quot;x&quot; &lt;&lt; zahl_6 &lt;&lt; &quot; ist &quot; &lt;&lt; ergebnis_mul &lt;&lt; endl;

			case'4':
			cout &lt;&lt; &quot;Bitte waehle deine erste Zahl aus: &quot;;
			float zahl_7;
			cin &gt;&gt; zahl_7;
			cout &lt;&lt; &quot;Bitte waehle deine zweite Zahl aus: &quot;;
			float zahl_8;
			cin &gt;&gt; zahl_8;
			float ergebnis_div;
			ergebnis_div = zahl_7 / zahl_8;
			cout &lt;&lt; &quot;Das Ergebnis von &quot; &lt;&lt; zahl_7 &lt;&lt; &quot;/&quot; &lt;&lt; zahl_8 &lt;&lt; &quot; ist &quot; &lt;&lt; ergebnis_div &lt;&lt; endl;	
	}

}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2385992</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2385992</guid><dc:creator><![CDATA[Deepimpact]]></dc:creator><pubDate>Sat, 01 Mar 2014 19:45:26 GMT</pubDate></item><item><title><![CDATA[Reply to switch case in eine Schleife setzen on Sat, 01 Mar 2014 19:52:59 GMT]]></title><description><![CDATA[<p>Deepimpact schrieb:</p>
<blockquote>
<p>Ich hab mir gedacht dass man dies in Form von einer Schleife machen kann.</p>
</blockquote>
<p>Das ist richtig. Hast du auch eine Frage?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2385993</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2385993</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Sat, 01 Mar 2014 19:52:59 GMT</pubDate></item><item><title><![CDATA[Reply to switch case in eine Schleife setzen on Sat, 01 Mar 2014 19:54:54 GMT]]></title><description><![CDATA[<p>Ja <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>Also mit welcher mache ich das und wie genau? Also wo muss ich sie hinsetzten?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2385995</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2385995</guid><dc:creator><![CDATA[Deepimpact]]></dc:creator><pubDate>Sat, 01 Mar 2014 19:54:54 GMT</pubDate></item><item><title><![CDATA[Reply to switch case in eine Schleife setzen on Sat, 01 Mar 2014 19:59:14 GMT]]></title><description><![CDATA[<pre><code>int main(void)
{
    cout &lt;&lt; &quot;1. Addition\n2. Subtraktion\n3. Multiplikation\n4. Division&quot; &lt;&lt; endl; 
	cout &lt;&lt; &quot;Du kannst jeder Zeit /q schreiben um das Programm zu beenden.&quot; &lt;&lt; endl; 

	char auswahl = 0; 
	while(auswahl != 'q')
	{
		cout &lt;&lt; endl &lt;&lt; &quot;Bitte waehle eine Rechenmethode aus\n&quot;;
		cin &gt;&gt; auswahl; 

		switch( auswahl )
                { 
		   // ...
		} 
	}
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2385996</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2385996</guid><dc:creator><![CDATA[DarkShadow44]]></dc:creator><pubDate>Sat, 01 Mar 2014 19:59:14 GMT</pubDate></item><item><title><![CDATA[Reply to switch case in eine Schleife setzen on Sat, 01 Mar 2014 20:06:49 GMT]]></title><description><![CDATA[<p>Wenn ich jetzt /q mache kommt 2 mal Bitte waehle eine Rechenmethode aus</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2385997</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2385997</guid><dc:creator><![CDATA[Deepimpact]]></dc:creator><pubDate>Sat, 01 Mar 2014 20:06:49 GMT</pubDate></item><item><title><![CDATA[Reply to switch case in eine Schleife setzen on Sat, 01 Mar 2014 20:26:28 GMT]]></title><description><![CDATA[<p>Wenn du die Schleife genauso geschrieben hast wie DarkShadow44, dann musst du nicht /q sondern nur q eingeben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2385999</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2385999</guid><dc:creator><![CDATA[RHCP_Drums]]></dc:creator><pubDate>Sat, 01 Mar 2014 20:26:28 GMT</pubDate></item><item><title><![CDATA[Reply to switch case in eine Schleife setzen on Sat, 01 Mar 2014 20:29:35 GMT]]></title><description><![CDATA[<blockquote>
<p>Wenn ich jetzt /q mache kommt 2 mal Bitte waehle eine Rechenmethode aus</p>
</blockquote>
<p>In einen char passt nur ein Zeichen. Wenn du zwei eingibst und dann Enter drückst wird nur der erste eingelesen. Dann beim nächsten Mal der zweite automatisch, weil noch was in cin steht von der letzten Eingabe. <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/2386000</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2386000</guid><dc:creator><![CDATA[DarkShadow44]]></dc:creator><pubDate>Sat, 01 Mar 2014 20:29:35 GMT</pubDate></item><item><title><![CDATA[Reply to switch case in eine Schleife setzen on Sat, 01 Mar 2014 20:30:52 GMT]]></title><description><![CDATA[<p>Hab es schon selbst gemerkt <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>Trotzdem danke für eure schnelle Hilfe</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2386001</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2386001</guid><dc:creator><![CDATA[Deepimpact]]></dc:creator><pubDate>Sat, 01 Mar 2014 20:30:52 GMT</pubDate></item></channel></rss>