<?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[Problem mit for&#x2F;if&#x2F;else]]></title><description><![CDATA[<p>HI</p>
<p>Ich versuche ein Programm zu schreiben, das n viele Dreiecke einliest. (Seiten a,b und c)<br />
Jedes Dreieck soll auf Gleichseitig &quot;anz2&quot; und Gleichschenkligkeit &quot;anz1&quot; überprüft werden. Am Ende soll die jeweilige Anzahl ausgegeben werden.</p>
<p>Das Programm läuft aber es wirft bei einigen Eingaben die falschen Werte raus. Nicht immer. Die Anzahl der Dreiecke, die 3 unterschiedlich lange Seiten haben, stimmt aber immer. Nur die beiden anderen bereiten mir Kopfzerbrechen.<br />
Meine Vermutung ist, dass die for/if/else Anweisungen anders funktionieren als ich mir das denke.<br />
Kann mir jemand helfen?</p>
<p>#include &lt;stdio.h&gt;<br />
#include &lt;stdlib.h&gt;</p>
<p>int n , i , anz1=0 , anz2=0 , m=0;</p>
<p>int main()<br />
{<br />
printf(&quot;Wieviele Dreiecke sollen getestet werden? &quot;); scanf(&quot;%i&quot;,&amp;n);</p>
<p>for (i=1;i&lt;=n;i++)<br />
{<br />
int a<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>i</mi><mo separator="true">,</mo><mi>b</mi></mrow><annotation encoding="application/x-tex">i,b</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.69444em;"></span><span class="strut bottom" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="base textstyle uncramped"><span class="mord mathit">i</span><span class="mpunct">,</span><span class="mord mathit">b</span></span></span></span>i,ci;  
printf("\\n\\nGeben Sie Seite a vom Dreieck %i ein! ",i);  
scanf("%i",&ai);<br />
printf(&quot;Geben Sie Seite b vom Dreieck %i ein! &quot;,i);<br />
scanf(&quot;%i&quot;,&amp;bi);  
printf("Geben Sie Seite c vom Dreieck %i ein! ",i);  
scanf("%i",&ci);<br />
if (a<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>i</mi><mo>=</mo><mo>=</mo><mi>b</mi></mrow><annotation encoding="application/x-tex">i==b</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.69444em;"></span><span class="strut bottom" style="height:0.69444em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathit">i</span><span class="mrel">=</span><span class="mrel">=</span><span class="mord mathit">b</span></span></span></span>i==c<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>i</mi><mo>)</mo><mi>a</mi><mi>n</mi><mi>z</mi><mn>2</mn><mo>+</mo><mo>+</mo><mo separator="true">;</mo><mi>e</mi><mi>l</mi><mi>s</mi><mi>e</mi><mi>i</mi><mi>f</mi><mo>(</mo><mi>a</mi></mrow><annotation encoding="application/x-tex">i)  
anz2++;  
else  
if (a</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.75em;"></span><span class="strut bottom" style="height:1em;vertical-align:-0.25em;"></span><span class="base textstyle uncramped"><span class="mord mathit">i</span><span class="mclose">)</span><span class="mord mathit">a</span><span class="mord mathit">n</span><span class="mord mathit" style="margin-right:0.04398em;">z</span><span class="mord mathrm">2</span><span class="mbin">+</span><span class="mord">+</span><span class="mpunct">;</span><span class="mord mathit">e</span><span class="mord mathit" style="margin-right:0.01968em;">l</span><span class="mord mathit">s</span><span class="mord mathit">e</span><span class="mord mathit">i</span><span class="mord mathit" style="margin-right:0.10764em;">f</span><span class="mopen">(</span><span class="mord mathit">a</span></span></span></span>i==b<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>i</mi><mi mathvariant="normal">∣</mi><mi mathvariant="normal">∣</mi><mi>a</mi></mrow><annotation encoding="application/x-tex">i || a</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.75em;"></span><span class="strut bottom" style="height:1em;vertical-align:-0.25em;"></span><span class="base textstyle uncramped"><span class="mord mathit">i</span><span class="mord mathrm">∣</span><span class="mord mathrm">∣</span><span class="mord mathit">a</span></span></span></span>i==c<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>i</mi><mi mathvariant="normal">∣</mi><mi mathvariant="normal">∣</mi><mi>b</mi></mrow><annotation encoding="application/x-tex">i || b</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.75em;"></span><span class="strut bottom" style="height:1em;vertical-align:-0.25em;"></span><span class="base textstyle uncramped"><span class="mord mathit">i</span><span class="mord mathrm">∣</span><span class="mord mathrm">∣</span><span class="mord mathit">b</span></span></span></span>i==c$i)<br />
anz1++;<br />
else<br />
m++;<br />
}</p>
<p>printf(&quot;\n\n\nSie haben %i Dreieck(e) eingegeben.\n&quot;,n);<br />
printf(&quot;%i davon war(en) gleichschenklig.\n&quot;,anz1);<br />
printf(&quot;%i davon war(en) gleichseitig.\n&quot;,anz2);<br />
printf(&quot;%i Dreieck(e) hatte(n) 3 unterschiedlich lange Seiten.\n\n&quot;,m);</p>
<p>system(&quot;pause&quot;);<br />
return 0;<br />
}</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/181351/problem-mit-for-if-else</link><generator>RSS for Node</generator><lastBuildDate>Tue, 22 Sep 2026 07:13:06 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/181351.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 12 May 2007 18:10:16 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problem mit for&#x2F;if&#x2F;else on Sat, 12 May 2007 18:10:16 GMT]]></title><description><![CDATA[<p>HI</p>
<p>Ich versuche ein Programm zu schreiben, das n viele Dreiecke einliest. (Seiten a,b und c)<br />
Jedes Dreieck soll auf Gleichseitig &quot;anz2&quot; und Gleichschenkligkeit &quot;anz1&quot; überprüft werden. Am Ende soll die jeweilige Anzahl ausgegeben werden.</p>
<p>Das Programm läuft aber es wirft bei einigen Eingaben die falschen Werte raus. Nicht immer. Die Anzahl der Dreiecke, die 3 unterschiedlich lange Seiten haben, stimmt aber immer. Nur die beiden anderen bereiten mir Kopfzerbrechen.<br />
Meine Vermutung ist, dass die for/if/else Anweisungen anders funktionieren als ich mir das denke.<br />
Kann mir jemand helfen?</p>
<p>#include &lt;stdio.h&gt;<br />
#include &lt;stdlib.h&gt;</p>
<p>int n , i , anz1=0 , anz2=0 , m=0;</p>
<p>int main()<br />
{<br />
printf(&quot;Wieviele Dreiecke sollen getestet werden? &quot;); scanf(&quot;%i&quot;,&amp;n);</p>
<p>for (i=1;i&lt;=n;i++)<br />
{<br />
int a<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>i</mi><mo separator="true">,</mo><mi>b</mi></mrow><annotation encoding="application/x-tex">i,b</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.69444em;"></span><span class="strut bottom" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="base textstyle uncramped"><span class="mord mathit">i</span><span class="mpunct">,</span><span class="mord mathit">b</span></span></span></span>i,ci;  
printf("\\n\\nGeben Sie Seite a vom Dreieck %i ein! ",i);  
scanf("%i",&ai);<br />
printf(&quot;Geben Sie Seite b vom Dreieck %i ein! &quot;,i);<br />
scanf(&quot;%i&quot;,&amp;bi);  
printf("Geben Sie Seite c vom Dreieck %i ein! ",i);  
scanf("%i",&ci);<br />
if (a<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>i</mi><mo>=</mo><mo>=</mo><mi>b</mi></mrow><annotation encoding="application/x-tex">i==b</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.69444em;"></span><span class="strut bottom" style="height:0.69444em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathit">i</span><span class="mrel">=</span><span class="mrel">=</span><span class="mord mathit">b</span></span></span></span>i==c<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>i</mi><mo>)</mo><mi>a</mi><mi>n</mi><mi>z</mi><mn>2</mn><mo>+</mo><mo>+</mo><mo separator="true">;</mo><mi>e</mi><mi>l</mi><mi>s</mi><mi>e</mi><mi>i</mi><mi>f</mi><mo>(</mo><mi>a</mi></mrow><annotation encoding="application/x-tex">i)  
anz2++;  
else  
if (a</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.75em;"></span><span class="strut bottom" style="height:1em;vertical-align:-0.25em;"></span><span class="base textstyle uncramped"><span class="mord mathit">i</span><span class="mclose">)</span><span class="mord mathit">a</span><span class="mord mathit">n</span><span class="mord mathit" style="margin-right:0.04398em;">z</span><span class="mord mathrm">2</span><span class="mbin">+</span><span class="mord">+</span><span class="mpunct">;</span><span class="mord mathit">e</span><span class="mord mathit" style="margin-right:0.01968em;">l</span><span class="mord mathit">s</span><span class="mord mathit">e</span><span class="mord mathit">i</span><span class="mord mathit" style="margin-right:0.10764em;">f</span><span class="mopen">(</span><span class="mord mathit">a</span></span></span></span>i==b<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>i</mi><mi mathvariant="normal">∣</mi><mi mathvariant="normal">∣</mi><mi>a</mi></mrow><annotation encoding="application/x-tex">i || a</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.75em;"></span><span class="strut bottom" style="height:1em;vertical-align:-0.25em;"></span><span class="base textstyle uncramped"><span class="mord mathit">i</span><span class="mord mathrm">∣</span><span class="mord mathrm">∣</span><span class="mord mathit">a</span></span></span></span>i==c<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>i</mi><mi mathvariant="normal">∣</mi><mi mathvariant="normal">∣</mi><mi>b</mi></mrow><annotation encoding="application/x-tex">i || b</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.75em;"></span><span class="strut bottom" style="height:1em;vertical-align:-0.25em;"></span><span class="base textstyle uncramped"><span class="mord mathit">i</span><span class="mord mathrm">∣</span><span class="mord mathrm">∣</span><span class="mord mathit">b</span></span></span></span>i==c$i)<br />
anz1++;<br />
else<br />
m++;<br />
}</p>
<p>printf(&quot;\n\n\nSie haben %i Dreieck(e) eingegeben.\n&quot;,n);<br />
printf(&quot;%i davon war(en) gleichschenklig.\n&quot;,anz1);<br />
printf(&quot;%i davon war(en) gleichseitig.\n&quot;,anz2);<br />
printf(&quot;%i Dreieck(e) hatte(n) 3 unterschiedlich lange Seiten.\n\n&quot;,m);</p>
<p>system(&quot;pause&quot;);<br />
return 0;<br />
}</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1283651</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1283651</guid><dc:creator><![CDATA[Valmar]]></dc:creator><pubDate>Sat, 12 May 2007 18:10:16 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit for&#x2F;if&#x2F;else on Sat, 12 May 2007 18:21:47 GMT]]></title><description><![CDATA[<p>Junge, bei dem Code hab' selbst ich noch was gelernt und ich progge C seit 1995.</p>
<p>Dollarzeichen in Variablennamen... öfter mal was Neues... aber gut... der GCC frisst's tatsächlich.</p>
<pre><code class="language-cpp">if (a$i==b$i==c$i)
</code></pre>
<p>heißt: a == b =&gt; (true oder false), es folgt (true oder false) == c.<br />
Das wird true, wenn a == b und c den Wert 1 besitzt oder a != b und c den Wert 0 besitzt.</p>
<p>Nehmen Sie diesen:</p>
<pre><code class="language-cpp">if (a$i==b$i &amp;&amp; b$i==c$i)
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1283655</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1283655</guid><dc:creator><![CDATA[Xin]]></dc:creator><pubDate>Sat, 12 May 2007 18:21:47 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit for&#x2F;if&#x2F;else on Sat, 12 May 2007 18:30:11 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;iostream&gt;

int main()
{
	std::cout &lt;&lt; &quot;Dreieck Validator V0.1&quot; &lt;&lt; std::endl;
	std::cout &lt;&lt; &quot;Wieviele Dreiecke sollen getestet werden? &quot; &lt;&lt; std::flush;
	std::size_t triangle_count = 0;
	std::cin &gt;&gt; triangle_count;

	std::size_t isosceles_triangles = 0;
	std::size_t equilateral_triangles = 0; 
	for (std::size_t triangle = 0; triangle &lt; triangle_count; ++triangle)
	{
		unsigned double sides[3] = {0, 0, 0};
		std::cout &lt;&lt; &quot;a: &quot; &lt;&lt; std::flush;
		std::cin &gt;&gt; sides[0];
		std::cout &lt;&lt; &quot;b: &quot; &lt;&lt; std::flush;
		std::cin &gt;&gt; sides[1];
		std::cout &lt;&lt; &quot;c: &quot; &lt;&lt; std::flush;
		std::cin &gt;&gt; sides[2];

		if (sides[0] == sides[1] &amp;&amp; sides[1] == sides[2])
			++equilateral_triangles;
		else if (sides[0] == sides[1] || sides[1] == sides[2] || sides[2] == sides[0])
			++isosceles_triangles;
	}
	std::cout &lt;&lt; equilateral_triangles &lt;&lt; &quot; Dreieck(e) war(en) gleichseitig&quot; &lt;&lt; std::endl;
	std::cout &lt;&lt; isosceles_triangles &lt;&lt; &quot; Dreieck(e) war(en) gleichschenklig&quot; &lt;&lt; std::endl;
	std::cout &lt;&lt; (triangle_count - equilateral_triangles - isosceles_triangles) &quot; war(en) invalid&quot; &lt;&lt; std::endl;
	return 0;
}
</code></pre>
<p>Wir sind hier im C++-Forum!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1283665</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1283665</guid><dc:creator><![CDATA[*D*Evil]]></dc:creator><pubDate>Sat, 12 May 2007 18:30:11 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit for&#x2F;if&#x2F;else on Sat, 12 May 2007 20:07:11 GMT]]></title><description><![CDATA[<p>Xin schrieb:</p>
<blockquote>
<p>Junge, bei dem Code hab' selbst ich noch was gelernt und ich progge C seit 1995.</p>
<p>Dollarzeichen in Variablennamen... öfter mal was Neues... aber gut... der GCC frisst's tatsächlich.</p>
</blockquote>
<p>Hatte ich irgendwann mal probiert als ich eine Geldsumme als Variable hatte.</p>
<p>Man lernt nie aus. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f4a1.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--light_bulb"
      title=":bulb:"
      alt="💡"
    /></p>
<p>So wie ich! Ich hatte mich so sehr auf die Schleife konzentriert, dass ich das total übersehen habe. Danke. Hat mir sehr geholfen. Geht jetzt super. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1283724</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1283724</guid><dc:creator><![CDATA[Valmar]]></dc:creator><pubDate>Sat, 12 May 2007 20:07:11 GMT</pubDate></item></channel></rss>