<?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[Durchlauf mehrerer if-Abfragen vermeiden]]></title><description><![CDATA[<p>Hallo Forengemeinde,</p>
<p>zunächst der obligatorische Hinweis, ich bin blutiger Anfänger und deshalb sehe ich nicht immer direkt für andere offensichtliche Fehler, ich bitte hiermit vorab um Entschuldigung.</p>
<p>Zu meinem Problem:</p>
<p>Ich habe hier einen ganzen Haufen if-Abfragen, die aufeinander folgen. Mein Problem ist nun, dass wenn ich eine Eingabe mache, die eigentlich nur eine Abfrage auslösen sollte, werden alle nacheinander ausgelöst. Das ganze sieht wie folgt aus:</p>
<pre><code class="language-cpp">int main (int argc, _TCHAR* argv[])
{
	string form_in;
	string form_out;
	string zahl_in;
	string zahl_out;

	cout &lt;&lt; &quot;ANWEISUNG: Bitte waehlen Sie das Format der einzugebenden Zahl:\n&quot;;
	cout &lt;&lt; &quot;1)Dezimal		2)Binaer	3)Hexadezimal	4)BCD\n&quot;;
	cin &gt;&gt; form_in;
	//Dezimal zu xyz
	if (form_in == &quot;1&quot;)
	{
		cout &lt;&lt; &quot;Bitte Format der Ausgabe wählen.\n&quot;;
		cout &lt;&lt; &quot;1)Dezimal		2)Binaer	3)Hexadezimal	4)BCD\n&quot;;
		cin &gt;&gt; form_out;
		if (form_out == &quot;1&quot;)
		{
		cout &lt;&lt; &quot;Unzulaessig.\n&quot;;
		system(&quot;PAUSE&quot;);
		}
		if (form_out == &quot;2&quot;)
		{
		cout &lt;&lt; &quot;Bitte geben Sie die gewuenschte zahl ein.\n&quot;;
		cin &gt;&gt; zahl_in;
		zahl_out = dez2bi(zahl_in);
		cout &lt;&lt; zahl_out;
		}
		if (form_out == &quot;3&quot;)
		{
		cout &lt;&lt; &quot;Bitte geben Sie die gewuenschte zahl ein.\n&quot;;
		cin &gt;&gt; zahl_in;
		zahl_out = dez2hex(zahl_in);
		cout &lt;&lt; zahl_out;
		}
		if (form_out == &quot;4&quot;)
		{
			cout &lt;&lt; &quot;Bitte geben Sie die gewuenschte zahl ein.\n&quot;;
			cin &gt;&gt; zahl_in;
			zahl_out = dez2bcd(zahl_in);
			cout &lt;&lt; zahl_out;
		}
	}
	//binaer zu xyz
	if (form_in == &quot;2&quot;);
	{
		cout &lt;&lt; &quot;Bitte Format der Ausgabe wählen.\n&quot;;
		cout &lt;&lt; &quot;1)Dezimal		2)Binaer	3)Hexadezimal	4)BCD\n&quot;;
		cin &gt;&gt; form_out;
		if (form_out == &quot;1&quot;)
		{
		cout &lt;&lt; &quot;Bitte geben Sie die gewuenschte zahl ein.\n&quot;;
		cin &gt;&gt; zahl_in;
		zahl_out = bi2dez(zahl_in);
		cout &lt;&lt; zahl_out;
		}
		if (form_out == &quot;2&quot;)
		{	
			cout &lt;&lt; &quot;Unzulaessig.\n&quot;;
			system(&quot;PAUSE&quot;);
		}
		if (form_out == &quot;3&quot;)
		{
			cout &lt;&lt; &quot;Bitte geben Sie die gewuenschte zahl ein.\n&quot;;
			cin &gt;&gt; zahl_in;
			zahl_out = bi2dez(zahl_in);
			zahl_out = dez2hex(zahl_out);
			cout &lt;&lt; zahl_out;
		}
		if (form_out == &quot;4&quot;)
		{
			cout &lt;&lt; &quot;Bitte geben Sie die gewuenschte zahl ein.\n&quot;;
			cin &gt;&gt; zahl_in;
			zahl_out = bi2dez(zahl_in);
			zahl_out = dez2bcd(zahl_out);
			cout &lt;&lt; zahl_out;
		}
	}
		//hexadezimal zu xzy	
		if (form_in == &quot;3&quot;);
		{
		cout &lt;&lt; &quot;Bitte Format der Ausgabe wählen.\n&quot;;
		cout &lt;&lt; &quot;1)Dezimal		2)Binaer	3)Hexadezimal	4)BCD\n&quot;;
		cin &gt;&gt; form_out;
		if (form_out == &quot;1&quot;)
		{
			cout &lt;&lt; &quot;Bitte geben Sie die gewuenschte zahl ein.\n&quot;;
			int ausnahme;
			cin &gt;&gt; ausnahme;
			zahl_out = toHex(ausnahme);
			cout &lt;&lt; zahl_out;
		}
		if (form_out == &quot;2&quot;)
		{
			cout &lt;&lt; &quot;Bitte geben Sie die gewuenschte zahl ein.\n&quot;;
			int ausnahme;
			cin &gt;&gt; ausnahme;
			zahl_out = toHex(ausnahme);
			zahl_out = dez2bi(zahl_out);
			cout &lt;&lt; zahl_out;
		}
		if (form_out == &quot;3&quot;)
		{
		cout &lt;&lt; &quot;Unzulaessig.\n&quot;;
		system(&quot;PAUSE&quot;);
		}
		if (form_out == &quot;4&quot;)
		{
		cout &lt;&lt; &quot;Bitte geben Sie die gewuenschte zahl ein.\n&quot;;
		int ausnahme;
		cin &gt;&gt; ausnahme;
		zahl_out = toHex(ausnahme);
		zahl_out = dez2bcd(zahl_out);
		cout &lt;&lt; zahl_out;
		}
		}
		// bcd zu xyz
		if (form_in == &quot;4&quot;)
		{
		cout &lt;&lt; &quot;Bitte Format der Ausgabe wählen.\n&quot;;
		cout &lt;&lt; &quot;1)Dezimal		2)Binaer	3)Hexadezimal	4)BCD\n&quot;;
		cin &gt;&gt; form_out;
		if (form_out == &quot;1&quot;)
		{
		cout &lt;&lt; &quot;Bitte geben Sie die gewuenschte zahl ein.\n&quot;;
		cin &gt;&gt; zahl_in;
		zahl_out = bcd2dez(zahl_in);
		cout &lt;&lt; zahl_out;
		}
		if (form_out == &quot;2&quot;)
		{
		cout &lt;&lt; &quot;Bitte geben Sie die gewuenschte zahl ein.\n&quot;;
		cin &gt;&gt; zahl_in;
		zahl_out = bcd2dez(zahl_in);
		zahl_out = dez2bi(zahl_out);
		cout &lt;&lt; zahl_out;
		}
		if (form_out == &quot;3&quot;)
		{
		cin &gt;&gt; zahl_in;
		zahl_out = bcd2dez(zahl_in);
		int aus_bcd;
		aus_bcd = atoi(zahl_out.c_str());
		//zahl_out = dez2hex(aus_bcd);
		/// asdasdasdasdadswichtig
		}
		if (form_out == &quot;4&quot;)
		{
		cout &lt;&lt; &quot;Unzulaessig.\n&quot;;
		system(&quot;PAUSE&quot;);
		}
		}

}
</code></pre>
<p>Habt ihr vieleicht eine Idee, wie ich es unterbinden kann, dass wenn eine Bedingung erfüllt wird, nicht gleich auch alle anderen abfragen bedient werden?</p>
<p>Beste Dank im Voraus.</p>
<p>teilzeitcoder</p>
<p>P.S: Ich hatte schon gesucht und ausprobiert, auch eine if-else abfrage hatte ich probiert, aber diese scheint nicht mit mehr als 2 Bedingungen zurecht zu kommen.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/304496/durchlauf-mehrerer-if-abfragen-vermeiden</link><generator>RSS for Node</generator><lastBuildDate>Sun, 09 Aug 2026 19:47:41 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/304496.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 07 Jun 2012 16:12:16 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Durchlauf mehrerer if-Abfragen vermeiden on Thu, 07 Jun 2012 16:12:16 GMT]]></title><description><![CDATA[<p>Hallo Forengemeinde,</p>
<p>zunächst der obligatorische Hinweis, ich bin blutiger Anfänger und deshalb sehe ich nicht immer direkt für andere offensichtliche Fehler, ich bitte hiermit vorab um Entschuldigung.</p>
<p>Zu meinem Problem:</p>
<p>Ich habe hier einen ganzen Haufen if-Abfragen, die aufeinander folgen. Mein Problem ist nun, dass wenn ich eine Eingabe mache, die eigentlich nur eine Abfrage auslösen sollte, werden alle nacheinander ausgelöst. Das ganze sieht wie folgt aus:</p>
<pre><code class="language-cpp">int main (int argc, _TCHAR* argv[])
{
	string form_in;
	string form_out;
	string zahl_in;
	string zahl_out;

	cout &lt;&lt; &quot;ANWEISUNG: Bitte waehlen Sie das Format der einzugebenden Zahl:\n&quot;;
	cout &lt;&lt; &quot;1)Dezimal		2)Binaer	3)Hexadezimal	4)BCD\n&quot;;
	cin &gt;&gt; form_in;
	//Dezimal zu xyz
	if (form_in == &quot;1&quot;)
	{
		cout &lt;&lt; &quot;Bitte Format der Ausgabe wählen.\n&quot;;
		cout &lt;&lt; &quot;1)Dezimal		2)Binaer	3)Hexadezimal	4)BCD\n&quot;;
		cin &gt;&gt; form_out;
		if (form_out == &quot;1&quot;)
		{
		cout &lt;&lt; &quot;Unzulaessig.\n&quot;;
		system(&quot;PAUSE&quot;);
		}
		if (form_out == &quot;2&quot;)
		{
		cout &lt;&lt; &quot;Bitte geben Sie die gewuenschte zahl ein.\n&quot;;
		cin &gt;&gt; zahl_in;
		zahl_out = dez2bi(zahl_in);
		cout &lt;&lt; zahl_out;
		}
		if (form_out == &quot;3&quot;)
		{
		cout &lt;&lt; &quot;Bitte geben Sie die gewuenschte zahl ein.\n&quot;;
		cin &gt;&gt; zahl_in;
		zahl_out = dez2hex(zahl_in);
		cout &lt;&lt; zahl_out;
		}
		if (form_out == &quot;4&quot;)
		{
			cout &lt;&lt; &quot;Bitte geben Sie die gewuenschte zahl ein.\n&quot;;
			cin &gt;&gt; zahl_in;
			zahl_out = dez2bcd(zahl_in);
			cout &lt;&lt; zahl_out;
		}
	}
	//binaer zu xyz
	if (form_in == &quot;2&quot;);
	{
		cout &lt;&lt; &quot;Bitte Format der Ausgabe wählen.\n&quot;;
		cout &lt;&lt; &quot;1)Dezimal		2)Binaer	3)Hexadezimal	4)BCD\n&quot;;
		cin &gt;&gt; form_out;
		if (form_out == &quot;1&quot;)
		{
		cout &lt;&lt; &quot;Bitte geben Sie die gewuenschte zahl ein.\n&quot;;
		cin &gt;&gt; zahl_in;
		zahl_out = bi2dez(zahl_in);
		cout &lt;&lt; zahl_out;
		}
		if (form_out == &quot;2&quot;)
		{	
			cout &lt;&lt; &quot;Unzulaessig.\n&quot;;
			system(&quot;PAUSE&quot;);
		}
		if (form_out == &quot;3&quot;)
		{
			cout &lt;&lt; &quot;Bitte geben Sie die gewuenschte zahl ein.\n&quot;;
			cin &gt;&gt; zahl_in;
			zahl_out = bi2dez(zahl_in);
			zahl_out = dez2hex(zahl_out);
			cout &lt;&lt; zahl_out;
		}
		if (form_out == &quot;4&quot;)
		{
			cout &lt;&lt; &quot;Bitte geben Sie die gewuenschte zahl ein.\n&quot;;
			cin &gt;&gt; zahl_in;
			zahl_out = bi2dez(zahl_in);
			zahl_out = dez2bcd(zahl_out);
			cout &lt;&lt; zahl_out;
		}
	}
		//hexadezimal zu xzy	
		if (form_in == &quot;3&quot;);
		{
		cout &lt;&lt; &quot;Bitte Format der Ausgabe wählen.\n&quot;;
		cout &lt;&lt; &quot;1)Dezimal		2)Binaer	3)Hexadezimal	4)BCD\n&quot;;
		cin &gt;&gt; form_out;
		if (form_out == &quot;1&quot;)
		{
			cout &lt;&lt; &quot;Bitte geben Sie die gewuenschte zahl ein.\n&quot;;
			int ausnahme;
			cin &gt;&gt; ausnahme;
			zahl_out = toHex(ausnahme);
			cout &lt;&lt; zahl_out;
		}
		if (form_out == &quot;2&quot;)
		{
			cout &lt;&lt; &quot;Bitte geben Sie die gewuenschte zahl ein.\n&quot;;
			int ausnahme;
			cin &gt;&gt; ausnahme;
			zahl_out = toHex(ausnahme);
			zahl_out = dez2bi(zahl_out);
			cout &lt;&lt; zahl_out;
		}
		if (form_out == &quot;3&quot;)
		{
		cout &lt;&lt; &quot;Unzulaessig.\n&quot;;
		system(&quot;PAUSE&quot;);
		}
		if (form_out == &quot;4&quot;)
		{
		cout &lt;&lt; &quot;Bitte geben Sie die gewuenschte zahl ein.\n&quot;;
		int ausnahme;
		cin &gt;&gt; ausnahme;
		zahl_out = toHex(ausnahme);
		zahl_out = dez2bcd(zahl_out);
		cout &lt;&lt; zahl_out;
		}
		}
		// bcd zu xyz
		if (form_in == &quot;4&quot;)
		{
		cout &lt;&lt; &quot;Bitte Format der Ausgabe wählen.\n&quot;;
		cout &lt;&lt; &quot;1)Dezimal		2)Binaer	3)Hexadezimal	4)BCD\n&quot;;
		cin &gt;&gt; form_out;
		if (form_out == &quot;1&quot;)
		{
		cout &lt;&lt; &quot;Bitte geben Sie die gewuenschte zahl ein.\n&quot;;
		cin &gt;&gt; zahl_in;
		zahl_out = bcd2dez(zahl_in);
		cout &lt;&lt; zahl_out;
		}
		if (form_out == &quot;2&quot;)
		{
		cout &lt;&lt; &quot;Bitte geben Sie die gewuenschte zahl ein.\n&quot;;
		cin &gt;&gt; zahl_in;
		zahl_out = bcd2dez(zahl_in);
		zahl_out = dez2bi(zahl_out);
		cout &lt;&lt; zahl_out;
		}
		if (form_out == &quot;3&quot;)
		{
		cin &gt;&gt; zahl_in;
		zahl_out = bcd2dez(zahl_in);
		int aus_bcd;
		aus_bcd = atoi(zahl_out.c_str());
		//zahl_out = dez2hex(aus_bcd);
		/// asdasdasdasdadswichtig
		}
		if (form_out == &quot;4&quot;)
		{
		cout &lt;&lt; &quot;Unzulaessig.\n&quot;;
		system(&quot;PAUSE&quot;);
		}
		}

}
</code></pre>
<p>Habt ihr vieleicht eine Idee, wie ich es unterbinden kann, dass wenn eine Bedingung erfüllt wird, nicht gleich auch alle anderen abfragen bedient werden?</p>
<p>Beste Dank im Voraus.</p>
<p>teilzeitcoder</p>
<p>P.S: Ich hatte schon gesucht und ausprobiert, auch eine if-else abfrage hatte ich probiert, aber diese scheint nicht mit mehr als 2 Bedingungen zurecht zu kommen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2220635</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2220635</guid><dc:creator><![CDATA[teilzeitcoder]]></dc:creator><pubDate>Thu, 07 Jun 2012 16:12:16 GMT</pubDate></item><item><title><![CDATA[Reply to Durchlauf mehrerer if-Abfragen vermeiden on Thu, 07 Jun 2012 16:17:17 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">if(...){
}
else if(...){
}
else if (...){
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2220639</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2220639</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Thu, 07 Jun 2012 16:17:17 GMT</pubDate></item><item><title><![CDATA[Reply to Durchlauf mehrerer if-Abfragen vermeiden on Thu, 07 Jun 2012 16:36:51 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">switch(...)
{
    case 1:
    break;
    case 2:
    break;
    ...
}
</code></pre>
<p>Gewöhn dir bei solchen Sachen lieber direkt <code>switch</code> - <code>case</code> an, das wird sonst nur unnötig unübersichtlich.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2220645</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2220645</guid><dc:creator><![CDATA[Ich bin Matrix...]]></dc:creator><pubDate>Thu, 07 Jun 2012 16:36:51 GMT</pubDate></item><item><title><![CDATA[Reply to Durchlauf mehrerer if-Abfragen vermeiden on Thu, 07 Jun 2012 16:41:57 GMT]]></title><description><![CDATA[<p>Danke für die schnellen Antworten <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":-)"
      alt="🙂"
    /></p>
<p>Das mit dem else if habe ich getestet, allerdings weißt mich mein Compiler darauf hin, dass ich &quot;else&quot; ohne dazugehöriges &quot;if&quot; benutze. Und wenn ich mit dem ersten if anfange und dann im Wechsel gehe, rutsche ich dennoch weiter durch.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2220648</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2220648</guid><dc:creator><![CDATA[teilzeitcoder]]></dc:creator><pubDate>Thu, 07 Jun 2012 16:41:57 GMT</pubDate></item><item><title><![CDATA[Reply to Durchlauf mehrerer if-Abfragen vermeiden on Thu, 07 Jun 2012 18:04:28 GMT]]></title><description><![CDATA[<p>teilzeitcoder schrieb:</p>
<blockquote>
<p>Danke für die schnellen Antworten <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":-)"
      alt="🙂"
    /></p>
<p>Das mit dem else if habe ich getestet, allerdings weißt mich mein Compiler darauf hin, dass ich &quot;else&quot; ohne dazugehöriges &quot;if&quot; benutze. Und wenn ich mit dem ersten if anfange und dann im Wechsel gehe, rutsche ich dennoch weiter durch.</p>
</blockquote>
<p>Selbstverständlich werden alle Tests bis zum ersten Treffer durchgeführt. Erst die folgenden Test werden übersprungen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2220679</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2220679</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Thu, 07 Jun 2012 18:04:28 GMT</pubDate></item><item><title><![CDATA[Reply to Durchlauf mehrerer if-Abfragen vermeiden on Fri, 08 Jun 2012 06:39:57 GMT]]></title><description><![CDATA[<p>teilzeitcoder schrieb:</p>
<blockquote>
<pre><code class="language-cpp">//binaer zu xyz
	if (form_in == &quot;2&quot;);
	...
	//hexadezimal zu xzy	
	if (form_in == &quot;3&quot;);
</code></pre>
</blockquote>
<p>Die Semikolons sind falsch. Dann sollte auch</p>
<pre><code class="language-cpp">else if
</code></pre>
<p>funktionieren</p>
<p>gruß<br />
stalker</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2220894</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2220894</guid><dc:creator><![CDATA[stalker]]></dc:creator><pubDate>Fri, 08 Jun 2012 06:39:57 GMT</pubDate></item><item><title><![CDATA[Reply to Durchlauf mehrerer if-Abfragen vermeiden on Fri, 08 Jun 2012 07:49:33 GMT]]></title><description><![CDATA[<p>Heißt es nicht Semikola oder Semikolone?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2220913</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2220913</guid><dc:creator><![CDATA[Kellerautomat]]></dc:creator><pubDate>Fri, 08 Jun 2012 07:49:33 GMT</pubDate></item><item><title><![CDATA[Reply to Durchlauf mehrerer if-Abfragen vermeiden on Fri, 08 Jun 2012 08:00:02 GMT]]></title><description><![CDATA[<p>Kellerautomat schrieb:</p>
<blockquote>
<p>Heißt es nicht Semikola oder Semikolone?</p>
</blockquote>
<p>laut Duden: Semikolons oder Semikola</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2220917</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2220917</guid><dc:creator><![CDATA[daddy_felix]]></dc:creator><pubDate>Fri, 08 Jun 2012 08:00:02 GMT</pubDate></item></channel></rss>