<?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[Wo steckt der Fehler?]]></title><description><![CDATA[<p>Hi Leute,</p>
<p>vorweg, ich bin ein totaler Newbie im Bereich der Programmierung. Ich wollte einen Befehl basteln, der mir zwei Zahlen addiert. Leider weiß ich nicht wo mein Fehler steckt, könnte mal jemand drüber schauen? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
<pre><code class="language-cpp">#include &lt;cstdlib&gt;
#include &lt;iostream&gt;
using namespace std;

int main(int argc, char *argv[])
{

    double Zahl1;
    double Zahl2;
    double Zahl3=Zahl1+Zahl2;

    cout&lt;&lt;&quot;Zahl eingeben: &quot;;
    cin&gt;&gt;Zahl1;
    cout&lt;&lt;&quot;Weitere Zahl eingeben: &quot;;
    cin&gt;&gt;Zahl2;
    cout&lt;&lt;&quot;Das Ergebnis ist: &quot;;
    cout&lt;&lt;Zahl3;

    getchar();

    system(&quot;PAUSE&quot;);
    return EXIT_SUCCESS;
}
</code></pre>
<p>Mir ist die Angelegenheit schon reicht peinlich, also habt etwas Nachsicht mit dem neuen. <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>Viele Grüße! <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/topic/307759/wo-steckt-der-fehler</link><generator>RSS for Node</generator><lastBuildDate>Thu, 06 Aug 2026 15:58:02 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/307759.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 04 Sep 2012 19:44:13 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Wo steckt der Fehler? on Tue, 04 Sep 2012 19:44:49 GMT]]></title><description><![CDATA[<p>Hi Leute,</p>
<p>vorweg, ich bin ein totaler Newbie im Bereich der Programmierung. Ich wollte einen Befehl basteln, der mir zwei Zahlen addiert. Leider weiß ich nicht wo mein Fehler steckt, könnte mal jemand drüber schauen? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
<pre><code class="language-cpp">#include &lt;cstdlib&gt;
#include &lt;iostream&gt;
using namespace std;

int main(int argc, char *argv[])
{

    double Zahl1;
    double Zahl2;
    double Zahl3=Zahl1+Zahl2;

    cout&lt;&lt;&quot;Zahl eingeben: &quot;;
    cin&gt;&gt;Zahl1;
    cout&lt;&lt;&quot;Weitere Zahl eingeben: &quot;;
    cin&gt;&gt;Zahl2;
    cout&lt;&lt;&quot;Das Ergebnis ist: &quot;;
    cout&lt;&lt;Zahl3;

    getchar();

    system(&quot;PAUSE&quot;);
    return EXIT_SUCCESS;
}
</code></pre>
<p>Mir ist die Angelegenheit schon reicht peinlich, also habt etwas Nachsicht mit dem neuen. <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>Viele Grüße! <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/2248508</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2248508</guid><dc:creator><![CDATA[hangman]]></dc:creator><pubDate>Tue, 04 Sep 2012 19:44:49 GMT</pubDate></item><item><title><![CDATA[Reply to Wo steckt der Fehler? on Tue, 04 Sep 2012 19:52:54 GMT]]></title><description><![CDATA[<p>hangman schrieb:</p>
<blockquote>
<p>Hi Leute,</p>
<p>vorweg, ich bin ein totaler Newbie im Bereich der Programmierung. Ich wollte einen Befehl basteln, der mir zwei Zahlen addiert. Leider weiß ich nicht wo mein Fehler steckt, könnte mal jemand drüber schauen? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
<p>Mir ist die Angelegenheit schon reicht peinlich, also habt etwas Nachsicht mit dem neuen. <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>
</blockquote>
<p>Hihi, der Fehler darf Dir auch peinlich sein, aber wir haben alle mal angefangen.</p>
<p>Du deklarierst Zahl1 und Zahl2. Welchen Wert die beiden haben, weiß niemand. Diese unbekannten Werte addierst Du dann und speicherst den Wert in Zahl3.</p>
<p>DANN erst fragst Du Zahl1 und Zahl2 vom User ab und gibst den addierten Wert der beiden unbekannten Zahlen aus.</p>
<p>Addiere die Zahlen erst nachdem Du sie eingegeben hast.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2248511</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2248511</guid><dc:creator><![CDATA[Xin]]></dc:creator><pubDate>Tue, 04 Sep 2012 19:52:54 GMT</pubDate></item><item><title><![CDATA[Reply to Wo steckt der Fehler? on Tue, 04 Sep 2012 20:04:03 GMT]]></title><description><![CDATA[<p>Oh man <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>
<pre><code class="language-cpp">#include &lt;cstdlib&gt;
#include &lt;iostream&gt;

using namespace std;

int main(int argc, char *argv[])
{

    double Zahl1;
    double Zahl2;

    cout&lt;&lt;&quot;Zahl eingeben: &quot;;
    cin&gt;&gt;Zahl1;
    cout&lt;&lt;&quot;Weitere Zahl eingeben: &quot;;
    cin&gt;&gt;Zahl2;
    cout&lt;&lt;&quot;Das Ergebnis ist: &quot;;

    double Zahl3=Zahl1+Zahl2;

    cout&lt;&lt;Zahl3;

    getchar();

    system(&quot;PAUSE&quot;);
    return EXIT_SUCCESS;
}
</code></pre>
<p>Jetzt klappt es auch, vielen Dank! <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 />
Ich finde es allerdings recht unschön. Schöner und übersichtlicher wäre es doch wenn man die Variablen alle über den kompletten Quellcode schreiben könnte oder funktioniert das garnicht? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2248512</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2248512</guid><dc:creator><![CDATA[hangman]]></dc:creator><pubDate>Tue, 04 Sep 2012 20:04:03 GMT</pubDate></item><item><title><![CDATA[Reply to Wo steckt der Fehler? on Tue, 04 Sep 2012 20:10:35 GMT]]></title><description><![CDATA[<p>klar kannst du alle Variablen oben drüber schreiben.<br />
nur die Berechnung muss eben unten im Code an die richtige Stelle.</p>
<p>Allerdings ist es empfehlenswerter Objekte erst da zu instanzieren, wo man sie auch verwendet.<br />
Da deine doubles aber einfache Datentypen sind, ist es da Wurst, ob du die am Anfang der Funktion deklarierst oder erst da, wo du sie auch verwendest.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2248513</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2248513</guid><dc:creator><![CDATA[DrakoXP]]></dc:creator><pubDate>Tue, 04 Sep 2012 20:10:35 GMT</pubDate></item><item><title><![CDATA[Reply to Wo steckt der Fehler? on Tue, 04 Sep 2012 20:12:36 GMT]]></title><description><![CDATA[<p>hangman schrieb:</p>
<blockquote>
<p>Oh man <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>Ich finde es allerdings recht unschön. Schöner und übersichtlicher wäre es doch wenn man die Variablen alle über den kompletten Quellcode schreiben könnte oder funktioniert das garnicht? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
</blockquote>
<p>In C++ ist es durchaus üblich Variablen erst dort zu definieren, wo sie benötigt werden. Bei überschaubaren Funktionen deklariere ich die Variablen allerdings auch ganz oben.</p>
<p>Eine grundsätzliche Regel würde ich hier nicht aufstellen, es sollte eben übersichtlich sein.</p>
<pre><code class="language-cpp">#include &lt;cstdlib&gt;
#include &lt;iostream&gt;

using namespace std;

int main(int argc, char *argv[])
{
    double Zahl1, Zahl2, Zahl3;

    cout&lt;&lt;&quot;Zahl eingeben: &quot;;
    cin&gt;&gt;Zahl1;

    cout&lt;&lt;&quot;Weitere Zahl eingeben: &quot;;
    cin&gt;&gt;Zahl2;

    Zahl3=Zahl1+Zahl2;
    cout&lt;&lt;&quot;Das Ergebnis ist: &quot;;
    cout&lt;&lt;Zahl3;

    getchar();

    system(&quot;PAUSE&quot;);
    return EXIT_SUCCESS;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2248514</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2248514</guid><dc:creator><![CDATA[Xin]]></dc:creator><pubDate>Tue, 04 Sep 2012 20:12:36 GMT</pubDate></item><item><title><![CDATA[Reply to Wo steckt der Fehler? on Tue, 04 Sep 2012 20:20:27 GMT]]></title><description><![CDATA[<p>Okay, vielen Dank für die Hilfe. Ich werde mich sicher noch des öfteren melden! <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>Viele Grüße! <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/2248515</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2248515</guid><dc:creator><![CDATA[hangman]]></dc:creator><pubDate>Tue, 04 Sep 2012 20:20:27 GMT</pubDate></item><item><title><![CDATA[Reply to Wo steckt der Fehler? on Wed, 05 Sep 2012 06:31:05 GMT]]></title><description><![CDATA[<p>Sollen Deine Programme auch z.B. auf Linux laufen, oder programmierst Du nur<br />
unter Windows?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2248549</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2248549</guid><dc:creator><![CDATA[redrew99]]></dc:creator><pubDate>Wed, 05 Sep 2012 06:31:05 GMT</pubDate></item><item><title><![CDATA[Reply to Wo steckt der Fehler? on Wed, 05 Sep 2012 07:32:34 GMT]]></title><description><![CDATA[<p>redrew99 schrieb:</p>
<blockquote>
<p>Sollen Deine Programme auch z.B. auf Linux laufen, oder programmierst Du nur<br />
unter Windows?</p>
</blockquote>
<p>Er ist Anfänger. Momentan sollen seine Programme überhaupt laufen. Alles andere später.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2248560</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2248560</guid><dc:creator><![CDATA[Xin]]></dc:creator><pubDate>Wed, 05 Sep 2012 07:32:34 GMT</pubDate></item><item><title><![CDATA[Reply to Wo steckt der Fehler? on Wed, 05 Sep 2012 07:50:30 GMT]]></title><description><![CDATA[<p>hangman schrieb:</p>
<blockquote>
<p>Schöner und übersichtlicher wäre es doch wenn man die Variablen alle über den kompletten Quellcode schreiben könnte</p>
</blockquote>
<p>Kann man, dass das übersichtlicher ist, sehe ich allerdings anders.</p>
<p>Ganz praktisch unbequem ist es dann, wenn man fremden Spaghetti-Code in Godfunktionen lesen darf, dann darf man kräftig scrollen, um die Deklarationen zu finden. Und es ist ja nicht immer ganz offensichtlich, was i,j,k,u,v sind (und selbst auf decltype(pFoo)=Foo* kann man sich ja nicht unbedingt verlassen).</p>
<p>Theoretisch unschön ist es allein schon deshalb, weil das bloße Vorhandensein einer Variablen i.d.R. keinen nützlichen Informationsgehalt hat. Zudem führt es zu unnötiger Überspezifizierung (ich nenne es mal &quot;magic types&quot;), wenn man ansonsten die Möglichkeit hätte, auto zu verwenden. Oft genug, spielt der konkrete Typ keine so große Rolle.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2248564</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2248564</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Wed, 05 Sep 2012 07:50:30 GMT</pubDate></item></channel></rss>