<?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[Einfaches Programm - Fehler]]></title><description><![CDATA[<p>Ich steh noch ziemlich am Anfang von C++. Ich wollte nun ein Programm schreiben was aus 4 Zahlen den Durchschnitt errechnet.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

using namespace std;

int main()

{  
	//Variablen
	float zahl1;
	float zahl2;
	float zahl3;
	float zahl4;
	float durchschnitt;

//Eingabe
	cout&lt;&lt;&quot;Zahl1:\t&quot;;
	cin&gt;&gt;zahl1;

	cout&lt;&lt;&quot;Zahl2:\t&quot;;
	cin&gt;&gt;zahl2;

	cout&lt;&lt;&quot;Zahl3:\t&quot;;
	cin&gt;&gt;zahl3;

	cout&lt;&lt;&quot;Zahl4:\t&quot;;
	cin&gt;&gt;zahl4;

	//Verarbeitung
	durchschnitt=zahl1+zahl2+zahl3+zahl4/4;

	//Ausgabe

	cout&lt;&lt;&quot;============================&quot;;

	cout&lt;&lt;&quot;Der Durchschnitt ist:\t&quot;&lt;&lt;durchschnitt&quot;&quot;;

	cin.get();

}
</code></pre>
<p>Wenn ich nun den Quelltext kompilieren will bekomme ich folgene Fehlermeldung:</p>
<blockquote>
<p>error C2143: Syntaxfehler: Es fehlt ';' vor 'Zeichenfolge'</p>
</blockquote>
<p>Der Fehler wird in der Zeile angezeigt:</p>
<blockquote>
<p>cout&lt;&lt;&quot;Der Durchschnitt ist:\t&quot;&gt;&gt;durchschnitt&quot;&quot;;</p>
</blockquote>
<p>Nun finde ich da jetzt den Fehler nicht.<br />
Könnte mir jemand erklären wo der Fehler liegt und wieso?</p>
<p>Ich bedanke mich schon mal.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/248405/einfaches-programm-fehler</link><generator>RSS for Node</generator><lastBuildDate>Thu, 17 Sep 2026 02:34:26 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/248405.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 24 Aug 2009 13:03:52 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Einfaches Programm - Fehler on Mon, 24 Aug 2009 13:03:52 GMT]]></title><description><![CDATA[<p>Ich steh noch ziemlich am Anfang von C++. Ich wollte nun ein Programm schreiben was aus 4 Zahlen den Durchschnitt errechnet.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

using namespace std;

int main()

{  
	//Variablen
	float zahl1;
	float zahl2;
	float zahl3;
	float zahl4;
	float durchschnitt;

//Eingabe
	cout&lt;&lt;&quot;Zahl1:\t&quot;;
	cin&gt;&gt;zahl1;

	cout&lt;&lt;&quot;Zahl2:\t&quot;;
	cin&gt;&gt;zahl2;

	cout&lt;&lt;&quot;Zahl3:\t&quot;;
	cin&gt;&gt;zahl3;

	cout&lt;&lt;&quot;Zahl4:\t&quot;;
	cin&gt;&gt;zahl4;

	//Verarbeitung
	durchschnitt=zahl1+zahl2+zahl3+zahl4/4;

	//Ausgabe

	cout&lt;&lt;&quot;============================&quot;;

	cout&lt;&lt;&quot;Der Durchschnitt ist:\t&quot;&lt;&lt;durchschnitt&quot;&quot;;

	cin.get();

}
</code></pre>
<p>Wenn ich nun den Quelltext kompilieren will bekomme ich folgene Fehlermeldung:</p>
<blockquote>
<p>error C2143: Syntaxfehler: Es fehlt ';' vor 'Zeichenfolge'</p>
</blockquote>
<p>Der Fehler wird in der Zeile angezeigt:</p>
<blockquote>
<p>cout&lt;&lt;&quot;Der Durchschnitt ist:\t&quot;&gt;&gt;durchschnitt&quot;&quot;;</p>
</blockquote>
<p>Nun finde ich da jetzt den Fehler nicht.<br />
Könnte mir jemand erklären wo der Fehler liegt und wieso?</p>
<p>Ich bedanke mich schon mal.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1765816</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1765816</guid><dc:creator><![CDATA[Gast23]]></dc:creator><pubDate>Mon, 24 Aug 2009 13:03:52 GMT</pubDate></item><item><title><![CDATA[Reply to Einfaches Programm - Fehler on Mon, 24 Aug 2009 13:06:25 GMT]]></title><description><![CDATA[<p>Welchen Zweck sollend die beiden Anführungszeichen am Ende der Zeile erfüllen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1765817</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1765817</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Mon, 24 Aug 2009 13:06:25 GMT</pubDate></item><item><title><![CDATA[Reply to Einfaches Programm - Fehler on Mon, 24 Aug 2009 13:07:54 GMT]]></title><description><![CDATA[<p>Ändere mal die Zeile</p>
<pre><code>cout&lt;&lt;&quot;Der Durchschnitt ist:\t&quot;&lt;&lt;durchschnitt&quot;&quot;;
</code></pre>
<p>in</p>
<pre><code>cout&lt;&lt;&quot;Der Durchschnitt ist:\t&quot;&lt;&lt;durchschnitt;
</code></pre>
<p>die sind einfach überflüssig.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1765819</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1765819</guid><dc:creator><![CDATA[endless]]></dc:creator><pubDate>Mon, 24 Aug 2009 13:07:54 GMT</pubDate></item><item><title><![CDATA[Reply to Einfaches Programm - Fehler on Mon, 24 Aug 2009 13:09:32 GMT]]></title><description><![CDATA[<p>Das wars, danke. Denn an einem anderen Computer habe ich mit Visual Studio 2005 gearbeitet. Da musste ich die &quot;&quot; setzen damit das Programm startete. An diesen Pc war es mit 2008. Da scheint es anders zu sein. Das muss ich mir nun merken. Danke für die schnellen Antworten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1765821</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1765821</guid><dc:creator><![CDATA[Gast23]]></dc:creator><pubDate>Mon, 24 Aug 2009 13:09:32 GMT</pubDate></item><item><title><![CDATA[Reply to Einfaches Programm - Fehler on Mon, 24 Aug 2009 13:10:10 GMT]]></title><description><![CDATA[<p>Seltsam hab ich noch nie gehö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>
]]></description><link>https://www.c-plusplus.net/forum/post/1765822</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1765822</guid><dc:creator><![CDATA[endless]]></dc:creator><pubDate>Mon, 24 Aug 2009 13:10:10 GMT</pubDate></item><item><title><![CDATA[Reply to Einfaches Programm - Fehler on Mon, 24 Aug 2009 13:48:03 GMT]]></title><description><![CDATA[<p>Deine Formel ist falsch:</p>
<pre><code class="language-cpp">durchschnitt=zahl1+zahl2+zahl3+zahl4/4;
</code></pre>
<p>Du musst Klammern setzen:</p>
<pre><code class="language-cpp">durchschnitt=(zahl1+zahl2+zahl3+zahl4)/4;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1765847</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1765847</guid><dc:creator><![CDATA[MiP]]></dc:creator><pubDate>Mon, 24 Aug 2009 13:48:03 GMT</pubDate></item><item><title><![CDATA[Reply to Einfaches Programm - Fehler on Mon, 24 Aug 2009 13:56:14 GMT]]></title><description><![CDATA[<p>Und du solltest dir vielleicht direkt angewöhnen, bei solchen Sachen durch einen Fließkommawert zu dividieren, also so:</p>
<pre><code class="language-cpp">durchschnitt=(zahl1+zahl2+zahl3+zahl4)/4.;  //4 ist ein double-Wert
</code></pre>
<p>oder so:</p>
<pre><code class="language-cpp">durchschnitt=(zahl1+zahl2+zahl3+zahl4)/4.f;  //4 ist ein float-Wert
</code></pre>
<p>In deinem Fall ist es zwar egal, da deine zahlx-Variablen schon float-Werte sind, aber beim nächsten Mal - wenn du einen Durchschnitt aus int-Variablen bilden willst - fliegst du vielleicht schon auf die Nase, weil das Ergebnis einer Ganzzahlendivision sich heftigst von dem einer FP-Division unterscheiden kann. Da hilft es auch nicht, das Ergebnis der Ganzzahlendivision einer float-Variable zuzuweisen. Nur so als Tipp für die Zukunft... <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>
]]></description><link>https://www.c-plusplus.net/forum/post/1765855</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1765855</guid><dc:creator><![CDATA[_matze]]></dc:creator><pubDate>Mon, 24 Aug 2009 13:56:14 GMT</pubDate></item></channel></rss>