<?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[Ordnen dreier Zahlen - If-Anweisungen falsch ?]]></title><description><![CDATA[<p>Abend,</p>
<p>Langsam gehe ich euch glaub ich auf die Nerven <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /><br />
Sitze schon seit 6h vor dem Computer und übe wie verrückt.<br />
Und manchmal kommen tükische Fehler, auf die ich keine Antwort finde :S<br />
Schlage im dicken Buch nach und finde nicht die Antwort nicht <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
<p>Der Compiler meldet mir 3x den Fehler:</p>
<blockquote>
<p>Zeile 27,39,51:<br />
Fehler 1 error C2181: Ungültiges 'else' ohne zugehöriges 'if'</p>
</blockquote>
<pre><code class="language-cpp">#include &lt;iostream&gt;

using namespace std;

int main() {

	int zahl1,
		zahl2,
		zahl3,
		zwsp;

	cout &lt;&lt; &quot;Gib die 1. Zahl ein!&quot; &lt;&lt; endl;
		cin &gt;&gt; zahl1;
	cout &lt;&lt; &quot;Gib die 2. Zahl ein!&quot; &lt;&lt; endl;
		cin &gt;&gt; zahl2;
	cout &lt;&lt; &quot;Gib die 3. Zahl ein!&quot; &lt;&lt; endl;
		cin &gt;&gt; zahl3;

	//1. Zahl Überprüfung
		if(zahl1 &gt; zahl2) {
			if(zahl1 &gt; zahl3)
				cout &lt;&lt; &quot;Größte: &quot; &lt;&lt; zahl1 &lt;&lt; endl;
				//2. Zahl ist Mittlere?
				if(zahl2 &gt; zahl3)
					cout &lt;&lt; &quot;Mittlere: &quot; &lt;&lt; zahl2 &lt;&lt; endl;
					cout &lt;&lt; &quot;Kleinste: &quot; &lt;&lt; zahl3 &lt;&lt; endl;
				else
					cout &lt;&lt; &quot;Mittlere: &quot; &lt;&lt; zahl3 &lt;&lt; endl;
					cout &lt;&lt; &quot;Kleinste: &quot; &lt;&lt; zahl2 &lt;&lt; endl;
		}	
		//2. Zahl Überprüfung
		else if(zahl2 &gt; zahl1) {
			if (zahl2 &gt; zahl3)
				cout &lt;&lt; &quot;Größte: &quot; &lt;&lt; zahl2 &lt;&lt; endl;
			//1. Zahl ist Mittlere?
			if(zahl1 &gt; zahl3)
				cout &lt;&lt; &quot;Mittlere: &quot; &lt;&lt; zahl1 &lt;&lt; endl;
				cout &lt;&lt; &quot;Kleinste: &quot; &lt;&lt; zahl3 &lt;&lt; endl;
			else
				cout &lt;&lt; &quot;Mittlere: &quot; &lt;&lt; zahl3 &lt;&lt; endl;
				cout &lt;&lt; &quot;Kleinste: &quot; &lt;&lt; zahl1 &lt;&lt; endl;
		}
		//3. Zahl Überprüfung
		else if(zahl3 &gt; zahl1) {
			if(zahl3 &gt; zahl2)
				cout &lt;&lt; &quot;Größte: &quot; &lt;&lt; zahl3 &lt;&lt; endl;
			//1. Zahl ist Mittlere?
			if(zahl1&gt;zahl2)
				cout &lt;&lt; &quot;Mittlere: &quot; &lt;&lt; zahl1 &lt;&lt; endl;
				cout &lt;&lt; &quot;Kleinste: &quot; &lt;&lt; zahl2 &lt;&lt; endl;
			else
				cout &lt;&lt; &quot;Mittlere: &quot; &lt;&lt; zahl2 &lt;&lt; endl;
				cout &lt;&lt; &quot;Kleinste: &quot; &lt;&lt; zahl1 &lt;&lt; endl;
		}
}
</code></pre>
<p>Lg Mentras</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/242346/ordnen-dreier-zahlen-if-anweisungen-falsch</link><generator>RSS for Node</generator><lastBuildDate>Mon, 21 Sep 2026 02:38:45 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/242346.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 02 Jun 2009 18:11:45 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Ordnen dreier Zahlen - If-Anweisungen falsch ? on Tue, 02 Jun 2009 18:11:45 GMT]]></title><description><![CDATA[<p>Abend,</p>
<p>Langsam gehe ich euch glaub ich auf die Nerven <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /><br />
Sitze schon seit 6h vor dem Computer und übe wie verrückt.<br />
Und manchmal kommen tükische Fehler, auf die ich keine Antwort finde :S<br />
Schlage im dicken Buch nach und finde nicht die Antwort nicht <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
<p>Der Compiler meldet mir 3x den Fehler:</p>
<blockquote>
<p>Zeile 27,39,51:<br />
Fehler 1 error C2181: Ungültiges 'else' ohne zugehöriges 'if'</p>
</blockquote>
<pre><code class="language-cpp">#include &lt;iostream&gt;

using namespace std;

int main() {

	int zahl1,
		zahl2,
		zahl3,
		zwsp;

	cout &lt;&lt; &quot;Gib die 1. Zahl ein!&quot; &lt;&lt; endl;
		cin &gt;&gt; zahl1;
	cout &lt;&lt; &quot;Gib die 2. Zahl ein!&quot; &lt;&lt; endl;
		cin &gt;&gt; zahl2;
	cout &lt;&lt; &quot;Gib die 3. Zahl ein!&quot; &lt;&lt; endl;
		cin &gt;&gt; zahl3;

	//1. Zahl Überprüfung
		if(zahl1 &gt; zahl2) {
			if(zahl1 &gt; zahl3)
				cout &lt;&lt; &quot;Größte: &quot; &lt;&lt; zahl1 &lt;&lt; endl;
				//2. Zahl ist Mittlere?
				if(zahl2 &gt; zahl3)
					cout &lt;&lt; &quot;Mittlere: &quot; &lt;&lt; zahl2 &lt;&lt; endl;
					cout &lt;&lt; &quot;Kleinste: &quot; &lt;&lt; zahl3 &lt;&lt; endl;
				else
					cout &lt;&lt; &quot;Mittlere: &quot; &lt;&lt; zahl3 &lt;&lt; endl;
					cout &lt;&lt; &quot;Kleinste: &quot; &lt;&lt; zahl2 &lt;&lt; endl;
		}	
		//2. Zahl Überprüfung
		else if(zahl2 &gt; zahl1) {
			if (zahl2 &gt; zahl3)
				cout &lt;&lt; &quot;Größte: &quot; &lt;&lt; zahl2 &lt;&lt; endl;
			//1. Zahl ist Mittlere?
			if(zahl1 &gt; zahl3)
				cout &lt;&lt; &quot;Mittlere: &quot; &lt;&lt; zahl1 &lt;&lt; endl;
				cout &lt;&lt; &quot;Kleinste: &quot; &lt;&lt; zahl3 &lt;&lt; endl;
			else
				cout &lt;&lt; &quot;Mittlere: &quot; &lt;&lt; zahl3 &lt;&lt; endl;
				cout &lt;&lt; &quot;Kleinste: &quot; &lt;&lt; zahl1 &lt;&lt; endl;
		}
		//3. Zahl Überprüfung
		else if(zahl3 &gt; zahl1) {
			if(zahl3 &gt; zahl2)
				cout &lt;&lt; &quot;Größte: &quot; &lt;&lt; zahl3 &lt;&lt; endl;
			//1. Zahl ist Mittlere?
			if(zahl1&gt;zahl2)
				cout &lt;&lt; &quot;Mittlere: &quot; &lt;&lt; zahl1 &lt;&lt; endl;
				cout &lt;&lt; &quot;Kleinste: &quot; &lt;&lt; zahl2 &lt;&lt; endl;
			else
				cout &lt;&lt; &quot;Mittlere: &quot; &lt;&lt; zahl2 &lt;&lt; endl;
				cout &lt;&lt; &quot;Kleinste: &quot; &lt;&lt; zahl1 &lt;&lt; endl;
		}
}
</code></pre>
<p>Lg Mentras</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1719894</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1719894</guid><dc:creator><![CDATA[Mentras]]></dc:creator><pubDate>Tue, 02 Jun 2009 18:11:45 GMT</pubDate></item><item><title><![CDATA[Reply to Ordnen dreier Zahlen - If-Anweisungen falsch ? on Tue, 02 Jun 2009 18:19:24 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>Zeile 22 und 24 sollen ja ausgeführt werden falls &quot;if(zahl1 &gt; zahl3)&quot; in Zeile 21 gilt.</p>
<p>Wenn du nach einer if-Abfrage jedoch keinen Block öffnenst ( mit { } ) wird nur die erste Zeile nach der if-Abfrage ausgeführt.</p>
<p>Ergo: Zusätzliche geschweifte Klammern einfügen.<br />
Selbe Verfahrensweise für &quot;2.Zahl&quot; und &quot;3.Zahl&quot; überprüfen.</p>
<p>Gruss!<br />
Dude</p>
<p>PS: Besonders effizient / schön ist der Code aber nicht <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/1719900</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1719900</guid><dc:creator><![CDATA[LaDispute]]></dc:creator><pubDate>Tue, 02 Jun 2009 18:19:24 GMT</pubDate></item><item><title><![CDATA[Reply to Ordnen dreier Zahlen - If-Anweisungen falsch ? on Tue, 02 Jun 2009 18:19:27 GMT]]></title><description><![CDATA[<p>Einrückung ist KEIN syntaktisches Element (das ist kein Python hier!), Du musst schon geschweifte Klammern setzen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1719901</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1719901</guid><dc:creator><![CDATA[SG1]]></dc:creator><pubDate>Tue, 02 Jun 2009 18:19:27 GMT</pubDate></item><item><title><![CDATA[Reply to Ordnen dreier Zahlen - If-Anweisungen falsch ? on Tue, 02 Jun 2009 18:21:12 GMT]]></title><description><![CDATA[<p>Tja, so ist C++ <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="🙂"
    /><br />
Allerdings hättest du nur auf die Synatx acht geben müssen:</p>
<pre><code class="language-cpp">if(...)
{ // Klammer auf
  // bla bla bla
} // Klammer zu
else
{ // Klammer auf
  // bla bla bla
} // Klammer zu
</code></pre>
<p>Wenn du keine geschweiften Klammern hinsetzt, dann passiert das:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

int main()
{
  if(false)
    std::cout &lt;&lt; &quot;Das kommt nicht!&quot; &lt;&lt; std::endl;
    std::cout &lt;&lt; &quot;Und das?&quot; &lt;&lt; std::endl;

  return 0;
}
</code></pre>
<p>Ich verrate es mal im voraus, das zweite kommt <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>
<p>Dieser &quot;Spezialfall&quot; schaut man sich am besten so an:</p>
<pre><code class="language-cpp">if(false) std::cout &lt;&lt; &quot;Das kommt nicht!&quot; &lt;&lt; std::endl;
// Semikolon, If-Bedingung zuende.
std::cout &lt;&lt; &quot;Und das?&quot; &lt;&lt; std::endl;
</code></pre>
<p>Mit Blöcken kann man halt mehrere Zeilen zusammennehmen. Es empfiehlt sich allerdings immer Blöcke zu nehmen, ist übersichtlicher und klarer <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>
<p>Grüssli</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1719903</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1719903</guid><dc:creator><![CDATA[Dravere]]></dc:creator><pubDate>Tue, 02 Jun 2009 18:21:12 GMT</pubDate></item><item><title><![CDATA[Reply to Ordnen dreier Zahlen - If-Anweisungen falsch ? on Tue, 02 Jun 2009 18:32:17 GMT]]></title><description><![CDATA[<p>Hmpf,...</p>
<p>Dravere, deine Posts sind immer hilfreich (Also, welche ich bis jetzt gelesen habe)</p>
<p>Ich hab ja extra Blöcke verwendet oder nicht?</p>
<pre><code class="language-cpp">//1. Zahl Überprüfung
		if(zahl1 &gt; zahl2) 
		{
			if(zahl1 &gt; zahl3)
				cout &lt;&lt; &quot;Größte: &quot; &lt;&lt; zahl1 &lt;&lt; endl;
				//2. Zahl ist Mittlere?
				if(zahl2 &gt; zahl3)
					cout &lt;&lt; &quot;Mittlere: &quot; &lt;&lt; zahl2 &lt;&lt; endl;
					cout &lt;&lt; &quot;Kleinste: &quot; &lt;&lt; zahl3 &lt;&lt; endl;
				else
					cout &lt;&lt; &quot;Mittlere: &quot; &lt;&lt; zahl3 &lt;&lt; endl;
					cout &lt;&lt; &quot;Kleinste: &quot; &lt;&lt; zahl2 &lt;&lt; endl;
		}
</code></pre>
<p>Hoffe jemand hat die Geduld um mir das noch genauer zu erklären (Also für den wirklichen Anfänger³...)</p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/21908">@LaDispute</a>:<br />
Jap, ich weiß, das der Code wirklich hässlich ist^^<br />
Könnte das ja dann mit dem ?-Operator machen...</p>
<p>Mir ist jetzt wichtig mich in den Schleifen, if-else, switch, usw... zu vertiefen... damit mir solche Missgeschicke nicht noch einmal passieren...</p>
<p>Lg Mentras</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1719910</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1719910</guid><dc:creator><![CDATA[Mentras]]></dc:creator><pubDate>Tue, 02 Jun 2009 18:32:17 GMT</pubDate></item><item><title><![CDATA[Reply to Ordnen dreier Zahlen - If-Anweisungen falsch ? on Tue, 02 Jun 2009 18:39:03 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/21128">@Mentras</a>,<br />
Jedes if-else braucht Blöcke, nicht nur das äusserste :p</p>
<p>Die Problematik dahinter ist nämlich relativ einfach. Whitespaces (Leerzeichen) werden ignoriert, hier mal etwas Pseudocode:</p>
<pre><code>if(a)
if(b)
...
else (1)
...
</code></pre>
<p>(1) Zu welchem if gehört dieses else? Deshalb verwendet man in C++ geschweifte Klammern, damit alles schön gebunden ist</p>
<pre><code class="language-cpp">if(a)
{
  if(b)
  {
  }
  else
  {
  }
}

// oder

if(a)
{
  if(b)
  {
  }
}
else
{
}
</code></pre>
<p>Andere Sprachen machen es anders, zum Beispiel die Makros in C und C++:</p>
<pre><code class="language-cpp">#if a
...
#if b
...
#else  // gehört zu b
...
#endif // gehört zu b

#endif // gehört zu a

// oder

#if a
...
#if b
...
#endif // gehört zu b
...
#else  // gehört zu a
...
#endif // gehört zu a
</code></pre>
<p>Grüssli</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1719917</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1719917</guid><dc:creator><![CDATA[Dravere]]></dc:creator><pubDate>Tue, 02 Jun 2009 18:39:03 GMT</pubDate></item><item><title><![CDATA[Reply to Ordnen dreier Zahlen - If-Anweisungen falsch ? on Tue, 02 Jun 2009 18:48:15 GMT]]></title><description><![CDATA[<p>Perfekt erklärt <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>Dank dir Dravere</p>
<p>fürDich: <a href="http://de.dreamstime.com/ich-liebe-dich-thumb22958.jpg" rel="nofollow">http://de.dreamstime.com/ich-liebe-dich-thumb22958.jpg</a></p>
<p>€dit: Den ?-Operator gibt es doch in C++ oder nicht? :S</p>
<p>Lg Mentras</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1719923</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1719923</guid><dc:creator><![CDATA[Mentras]]></dc:creator><pubDate>Tue, 02 Jun 2009 18:48:15 GMT</pubDate></item><item><title><![CDATA[Reply to Ordnen dreier Zahlen - If-Anweisungen falsch ? on Tue, 02 Jun 2009 18:49:23 GMT]]></title><description><![CDATA[<p>Dravere hat dir sicher schon gut erklärt wozu du Blöcke brauchst. Für den Lerneffekt ist es am besten wenn du jetzt selbst überlegst welche Bereiche du mit {} kapseln musst.</p>
<p>Zur Effizient deines Codes: Natürlich ist es bei heutigen Prozessoren egal, ob man ein wenig umständlich programmiert.<br />
Stelle dir aber vor, es wird nicht einfach nur ein Satz ausgegeben oder eine einfach Bedingung gecheckt sondern stattdessen tatsächliche Rechenlast erzeugt von deiner if-Anweisung (zB Videobearbeitung, komplexe wissenschaftliche/numerische Anwendungen) dann bist du gut beraten vorher das Problem zu durchdenken bevor du mit dem Programmieren anfängst.</p>
<p>Du hast einfach eine Menge Redundanz in deinem Code.</p>
<p>Eine kleine Frage am Rande: Was wird denn ausgeben wenn zahl1 und zahl2 gleichgroß sind?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1719926</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1719926</guid><dc:creator><![CDATA[LaDispute]]></dc:creator><pubDate>Tue, 02 Jun 2009 18:49:23 GMT</pubDate></item><item><title><![CDATA[Reply to Ordnen dreier Zahlen - If-Anweisungen falsch ? on Tue, 02 Jun 2009 18:56:21 GMT]]></title><description><![CDATA[<p>War mir klar, je weniger Schaltungen, desto schneller ist das Programm...</p>
<p>Jap, das muss ich noch einbauen, allerdings wird mir das zuviel &quot;if-elseif-else&quot;...</p>
<p>Hat C++ den &quot;(a &gt; b) ? a : b &quot; Operator noch?<br />
Dann könnte ich mir solche if-else ersparen...</p>
<p>Lg Mentras</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1719930</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1719930</guid><dc:creator><![CDATA[Mentras]]></dc:creator><pubDate>Tue, 02 Jun 2009 18:56:21 GMT</pubDate></item><item><title><![CDATA[Reply to Ordnen dreier Zahlen - If-Anweisungen falsch ? on Tue, 02 Jun 2009 18:56:29 GMT]]></title><description><![CDATA[<p>LaDispute schrieb:</p>
<blockquote>
<p>Eine kleine Frage am Rande: Was wird denn ausgeben wenn zahl1 und zahl2 gleichgroß sind?</p>
</blockquote>
<p>Und was, wenn zahl1 und zahl2 verschieden, zahl3 aber die größte ist?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1719931</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1719931</guid><dc:creator><![CDATA[SG1]]></dc:creator><pubDate>Tue, 02 Jun 2009 18:56:29 GMT</pubDate></item><item><title><![CDATA[Reply to Ordnen dreier Zahlen - If-Anweisungen falsch ? on Tue, 02 Jun 2009 19:02:46 GMT]]></title><description><![CDATA[<p>&quot;(a &gt; b) ? a : b&quot; kannst du zwar verwenden, wirklich lesbar wird dein Code dadurch aber auch nicht. Und Lesbarkeit ist genau das, was man sich wünscht wenn man nach einem halben Jahr wieder mal in Code reinschaut.</p>
<p>Zudem: Wenn du beim Erfüllen / Nichterfüllen deines Vergleiches mehr als eine Zeile Code ausführen möchtest, kommst du ums Kapseln sowieso nicht drumrum.</p>
<p>C++ und ?:<br />
<a href="http://en.wikipedia.org/wiki/Conditional_operator#C.2B.2B" rel="nofollow">http://en.wikipedia.org/wiki/Conditional_operator#C.2B.2B</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1719934</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1719934</guid><dc:creator><![CDATA[LaDispute]]></dc:creator><pubDate>Tue, 02 Jun 2009 19:02:46 GMT</pubDate></item><item><title><![CDATA[Reply to Ordnen dreier Zahlen - If-Anweisungen falsch ? on Tue, 02 Jun 2009 19:13:34 GMT]]></title><description><![CDATA[<p>Die Verschönerungsvorschläge sind zwar angebracht, aber ich weiss nicht, ob es dafür nicht noch zu früh ist <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>Ich meine, am schönsten wäre hier ein kleines Array, ein <code>std::sort</code> aus der Standardbibliothek und eine Ausgabe des Arrays. Das wären dann noch ca. 10 Zeilen und überhaupt keine if-else Dinge <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>
<p>Es ist sicher gut mal zu sagen, dass man schönen Code schreiben sollte, aber ein Anfänger sollte vielleicht auch einfach zuerst mal die Sprache vollständig erlernen. Denn erst später hat man mehr und mehr Wissen, welches man einsetzen kann, um Code zu verschönern.</p>
<p>Meint ihr nicht auch?</p>
<p>Grüssli</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1719936</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1719936</guid><dc:creator><![CDATA[Dravere]]></dc:creator><pubDate>Tue, 02 Jun 2009 19:13:34 GMT</pubDate></item><item><title><![CDATA[Reply to Ordnen dreier Zahlen - If-Anweisungen falsch ? on Tue, 02 Jun 2009 19:59:40 GMT]]></title><description><![CDATA[<p>Da hast du natürlich Recht. Am Anfang soll man gerne &quot;sinnlose&quot; Dinge programmieren, oder vielleicht auch umständliche um dann zu verstehen, wie es einfacher ginge. Mir geht es ja nicht um &quot;schönen Code&quot;.</p>
<p>Es ist meiner Meinung einfach von Anfang an wichtig die Probleme vorher zu durchdenken. Man lernt so nämlich &quot;Programmieren/Problemlösen&quot; anstatt &quot;nur&quot; C++</p>
<p>Workflow und analytisches Denken sind wichtiger als Operator XYZ zu kennen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1719951</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1719951</guid><dc:creator><![CDATA[LaDispute]]></dc:creator><pubDate>Tue, 02 Jun 2009 19:59:40 GMT</pubDate></item><item><title><![CDATA[Reply to Ordnen dreier Zahlen - If-Anweisungen falsch ? on Tue, 02 Jun 2009 20:00:27 GMT]]></title><description><![CDATA[<p>LaDispute schrieb:</p>
<blockquote>
<p>&quot;(a &gt; b) ? a : b&quot; kannst du zwar verwenden, wirklich lesbar wird dein Code dadurch aber auch nicht.</p>
</blockquote>
<p>Das ist Ansichtssache. Ich mag zum Teil kompakten Code, und finde auch, er kann die Lesbarkeit erhöhen. Für gewisse Dinge ist der <code>operator?:</code> sogar notwendig. Zwei Beispiele:</p>
<p><strong>1. Anweisungen im gleichen Scope.</strong><br />
Das folgende Beispiel funktioniert mit <code>if</code> nicht, ohne ein standardkonstruiertes Objekt, Zeiger oder den Zuweisungsoperator zu verwenden.</p>
<pre><code class="language-cpp">MyClass Var = Condition ? MyClass(&quot;hoi&quot;) : MyClass('t', 4);
</code></pre>
<p><strong>2. Template-Metaprogrammierung.</strong><br />
Zur Kompilierzeit gibt es kein <code>if</code> . Da behilft man sich unter anderem mit <code>operator?:</code> bei boolschen Bedingungen.</p>
<pre><code class="language-cpp">template &lt;int N&gt;
struct abs
{
    static const int value = (N &gt;= 0) ? N : -N;
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1719955</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1719955</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Tue, 02 Jun 2009 20:00:27 GMT</pubDate></item><item><title><![CDATA[Reply to Ordnen dreier Zahlen - If-Anweisungen falsch ? on Tue, 02 Jun 2009 20:06:55 GMT]]></title><description><![CDATA[<p>Ich gib´s zu,...</p>
<p>Der Code wurde mir zu unübersichtlich.</p>
<p>STRG + A und dann ENTF...</p>
<p>Morgen mach ich´s mit einer hübschen Funktion...</p>
<p>Lg Mentras</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1719960</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1719960</guid><dc:creator><![CDATA[Mentras]]></dc:creator><pubDate>Tue, 02 Jun 2009 20:06:55 GMT</pubDate></item><item><title><![CDATA[Reply to Ordnen dreier Zahlen - If-Anweisungen falsch ? on Tue, 02 Jun 2009 20:20:29 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/12954">@Nexus</a>: Absolut richtig. Ging aber eher um den konkreten Fall hier und das Erlernen von Kapselung.</p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/21128">@Mentras</a>: Strg+S danach nicht vergessen <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/1719967</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1719967</guid><dc:creator><![CDATA[LaDispute]]></dc:creator><pubDate>Tue, 02 Jun 2009 20:20:29 GMT</pubDate></item></channel></rss>