<?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[Fehler bei Programmmodularisierung und Referenzparametern]]></title><description><![CDATA[<p>Ich bin Programmieranfänger und habe Probleme bei einer Aufgabe zum Thema Programmmodularisierung.Das ist meine erste Aufgabe zum Thema Programmmodularisierung und<br />
Referenzparametern, daher denke ich , dass ich irgendwo einen grundlegenden Fehler gemacht habe. Bin leider im Umgang noch nicht sehr erfahren.<br />
Ich verwende VS 2015.</p>
<p>Das Programm soll zwei Zahlen entgegennehmen und noch Rechenoption + oder -<br />
und diese dann Verrechnen. Quasi ein kleiner Taschenrechner.<br />
Man soll bestimmte headerdateien und namespaces verwenden.<br />
Man soll eine EInlesefunktion, eine Berechnungsfunktion und eine<br />
Ausgabefunktion schreiben. Sodass man quasi im mainprogramm nur Funktionen<br />
stehen hat.</p>
<p>Ich habe zunächst im Headerdateien Ordner meines Projektes eine gui.h Datei<br />
erstellt. Nun habe ich im Quelldateienordner gui.cpp und meine main.cpp erstellt.</p>
<p>Die zwei Zahlen sind im Format das man erst die Zehnerstelle von Zahl eins eingibt und dann die Einerstelle von Zahl eins. Ebenso für die zweite Zahl. Daher 4 int Zahlen<br />
und 1 char Variable für + und -.<br />
Da man bei Funktionen ja nur einen Rückgabewert nehmen kann und wir noch<br />
den char typ haben braucht man noch Referenzparameter.</p>
<p>Ich habe nun erstmal meine eingabe() funktion geschrieben<br />
und wollte diese zunächst im main programm mal testen. Jedoch<br />
bekomme ich bei Zahleingaben keinen Schleifenfortschritt und bei<br />
Zeichen lande ich direkt in einer Endlosschleife.<br />
Ich hoffe mir kann jemand helfen und mir meine Fehler aufzeigen.</p>
<pre><code>// meine gui.h datei
#pragma once

namespace gui
{

        int eingabe(int &amp;x, int &amp;x1, int &amp;y, int &amp;y1, char &amp;z);
}
</code></pre>
<pre><code>/meine gui.cpp datei
#include &quot;gui.h&quot;
#include &lt;iostream&gt;
using namespace std;

 namespace gui
{

        void printout(int)
        {

        }
        int eingabe(int &amp;x, int &amp;x1, int &amp;y, int &amp;y1, char &amp;z)
        {
                int charwert = 0;

                for (int  i = 0; i &lt; 5; i++)
                {

                        if (i == 0)
                        {
                                cout &lt;&lt; &quot;Geben Sie die 1. Ziffer der 1. Zahl ein: &quot;;
                                cin &gt;&gt; x;
                                if (x != 0 || x != 1 || x != 2 || x != 3 || x != 4 || x != 5 || x != 6 || x != 7 || x != 8 || x != 9  )
                                {
                                        i--;
                                        continue;
                                }

                        }
                        if (i == 1)
                        {
                                cout &lt;&lt; &quot;Geben Sie die 2. Ziffer der 1. Zahl ein: &quot;;
                                cin &gt;&gt; x1;
                                if (x1 != 0 || x1 != 1 || x1 != 2 || x1 != 3 || x1 != 4 || x1 != 5 || x1 != 6 || x1 != 7 || x1 != 8 || x1 != 9  )
                                {
                                        i--;
                                        continue;
                                }
                        }
                        if (i == 2)
                        {
                                cout &lt;&lt; &quot;Geben Sie die 1. Ziffer der 2. Zahl ein: &quot;;
                                cin &gt;&gt; y;
                                if (y != 0 || y != 1 || y != 2 || y != 3 || y != 4 || y != 5 || y != 6 || y != 7 || y != 8 || y != 9)
                                {
                                        i--;
                                        continue;
                                }
                        }
                        if (i == 3)
                        {
                                cout &lt;&lt; &quot;Geben Sie die 2. Ziffer der 1. Zahl ein: &quot;;
                                cin &gt;&gt; y1;
                                if (y1 != 0 || y1 != 1 || y1 != 2 || y1 != 3 || y1 != 4 || y1 != 5 || y1 != 6 || y1 != 7 || y1 != 8 || y1 != 9)
                                {
                                        i--;
                                        continue;
                                }
                        }
                        if (i==4)
                        {
                                cout &lt;&lt; &quot;Geben Sie die Rechenoperation ein (+ oder -) : &quot;;
                                cin &gt;&gt; z;
                                if (z != '+' || z != '-' )
                                {
                                        i--;
                                        continue;
                                }
                                int charwert = 0;
                                if( z == '+')
                                {
                                        charwert = 0;
                                }
                                else
                                {
                                        charwert = 1;
                                }

                        }

                }

                return x,x1,y,y1,charwert;
        }
}
</code></pre>
<pre><code>// mein maiprogramm

#include &lt;iostream&gt;
#include &quot;gui.h&quot;
#include &quot;calc.h&quot;
using namespace std;

int main()
{

        int zahl1_wert1 =0;
        int zahl1_wert2=0;
        int zahl2_wert1=0;
        int zahl2_wert2=0;
        char a ;

        gui::eingabe(zahl1_wert1,zahl1_wert2,zahl2_wert1,zahl2_wert2,a);

        system(&quot;PAUSE&quot;);
        return 0;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/335581/fehler-bei-programmmodularisierung-und-referenzparametern</link><generator>RSS for Node</generator><lastBuildDate>Fri, 24 Apr 2026 10:59:17 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/335581.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 27 Nov 2015 17:37:23 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Fehler bei Programmmodularisierung und Referenzparametern on Fri, 27 Nov 2015 17:40:07 GMT]]></title><description><![CDATA[<p>Ich bin Programmieranfänger und habe Probleme bei einer Aufgabe zum Thema Programmmodularisierung.Das ist meine erste Aufgabe zum Thema Programmmodularisierung und<br />
Referenzparametern, daher denke ich , dass ich irgendwo einen grundlegenden Fehler gemacht habe. Bin leider im Umgang noch nicht sehr erfahren.<br />
Ich verwende VS 2015.</p>
<p>Das Programm soll zwei Zahlen entgegennehmen und noch Rechenoption + oder -<br />
und diese dann Verrechnen. Quasi ein kleiner Taschenrechner.<br />
Man soll bestimmte headerdateien und namespaces verwenden.<br />
Man soll eine EInlesefunktion, eine Berechnungsfunktion und eine<br />
Ausgabefunktion schreiben. Sodass man quasi im mainprogramm nur Funktionen<br />
stehen hat.</p>
<p>Ich habe zunächst im Headerdateien Ordner meines Projektes eine gui.h Datei<br />
erstellt. Nun habe ich im Quelldateienordner gui.cpp und meine main.cpp erstellt.</p>
<p>Die zwei Zahlen sind im Format das man erst die Zehnerstelle von Zahl eins eingibt und dann die Einerstelle von Zahl eins. Ebenso für die zweite Zahl. Daher 4 int Zahlen<br />
und 1 char Variable für + und -.<br />
Da man bei Funktionen ja nur einen Rückgabewert nehmen kann und wir noch<br />
den char typ haben braucht man noch Referenzparameter.</p>
<p>Ich habe nun erstmal meine eingabe() funktion geschrieben<br />
und wollte diese zunächst im main programm mal testen. Jedoch<br />
bekomme ich bei Zahleingaben keinen Schleifenfortschritt und bei<br />
Zeichen lande ich direkt in einer Endlosschleife.<br />
Ich hoffe mir kann jemand helfen und mir meine Fehler aufzeigen.</p>
<pre><code>// meine gui.h datei
#pragma once

namespace gui
{

        int eingabe(int &amp;x, int &amp;x1, int &amp;y, int &amp;y1, char &amp;z);
}
</code></pre>
<pre><code>/meine gui.cpp datei
#include &quot;gui.h&quot;
#include &lt;iostream&gt;
using namespace std;

 namespace gui
{

        void printout(int)
        {

        }
        int eingabe(int &amp;x, int &amp;x1, int &amp;y, int &amp;y1, char &amp;z)
        {
                int charwert = 0;

                for (int  i = 0; i &lt; 5; i++)
                {

                        if (i == 0)
                        {
                                cout &lt;&lt; &quot;Geben Sie die 1. Ziffer der 1. Zahl ein: &quot;;
                                cin &gt;&gt; x;
                                if (x != 0 || x != 1 || x != 2 || x != 3 || x != 4 || x != 5 || x != 6 || x != 7 || x != 8 || x != 9  )
                                {
                                        i--;
                                        continue;
                                }

                        }
                        if (i == 1)
                        {
                                cout &lt;&lt; &quot;Geben Sie die 2. Ziffer der 1. Zahl ein: &quot;;
                                cin &gt;&gt; x1;
                                if (x1 != 0 || x1 != 1 || x1 != 2 || x1 != 3 || x1 != 4 || x1 != 5 || x1 != 6 || x1 != 7 || x1 != 8 || x1 != 9  )
                                {
                                        i--;
                                        continue;
                                }
                        }
                        if (i == 2)
                        {
                                cout &lt;&lt; &quot;Geben Sie die 1. Ziffer der 2. Zahl ein: &quot;;
                                cin &gt;&gt; y;
                                if (y != 0 || y != 1 || y != 2 || y != 3 || y != 4 || y != 5 || y != 6 || y != 7 || y != 8 || y != 9)
                                {
                                        i--;
                                        continue;
                                }
                        }
                        if (i == 3)
                        {
                                cout &lt;&lt; &quot;Geben Sie die 2. Ziffer der 1. Zahl ein: &quot;;
                                cin &gt;&gt; y1;
                                if (y1 != 0 || y1 != 1 || y1 != 2 || y1 != 3 || y1 != 4 || y1 != 5 || y1 != 6 || y1 != 7 || y1 != 8 || y1 != 9)
                                {
                                        i--;
                                        continue;
                                }
                        }
                        if (i==4)
                        {
                                cout &lt;&lt; &quot;Geben Sie die Rechenoperation ein (+ oder -) : &quot;;
                                cin &gt;&gt; z;
                                if (z != '+' || z != '-' )
                                {
                                        i--;
                                        continue;
                                }
                                int charwert = 0;
                                if( z == '+')
                                {
                                        charwert = 0;
                                }
                                else
                                {
                                        charwert = 1;
                                }

                        }

                }

                return x,x1,y,y1,charwert;
        }
}
</code></pre>
<pre><code>// mein maiprogramm

#include &lt;iostream&gt;
#include &quot;gui.h&quot;
#include &quot;calc.h&quot;
using namespace std;

int main()
{

        int zahl1_wert1 =0;
        int zahl1_wert2=0;
        int zahl2_wert1=0;
        int zahl2_wert2=0;
        char a ;

        gui::eingabe(zahl1_wert1,zahl1_wert2,zahl2_wert1,zahl2_wert2,a);

        system(&quot;PAUSE&quot;);
        return 0;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2477350</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2477350</guid><dc:creator><![CDATA[as1as]]></dc:creator><pubDate>Fri, 27 Nov 2015 17:40:07 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler bei Programmmodularisierung und Referenzparametern on Fri, 27 Nov 2015 18:23:01 GMT]]></title><description><![CDATA[<p>Nenne einen Wert von x, bei dem nicht i--; continue ausgeführt wird.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2477359</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2477359</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Fri, 27 Nov 2015 18:23:01 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler bei Programmmodularisierung und Referenzparametern on Fri, 27 Nov 2015 19:09:58 GMT]]></title><description><![CDATA[<p>manni66 schrieb:</p>
<blockquote>
<p>Nenne einen Wert von x, bei dem nicht i--; continue ausgeführt wird.</p>
</blockquote>
<p>Ohh, da hatte ich wohl einen Logicfehler drinne. Danke:)<br />
Hab es nun gefixt und nun funktioniert es bei Zahleingaben. Jedoch bekomme ich bei Zeicheneingabe immer noch die Endlosschleife. Ich sehe leider nicht warum.</p>
<pre><code>#include &quot;gui.h&quot;
#include &lt;iostream&gt;
using namespace std;

 namespace gui
{

        void printout(int)
        {

        }
        int eingabe(int &amp;x, int &amp;x1, int &amp;y, int &amp;y1, char &amp;z)
        {
                int charwert = 0;

                for (int  i = 0; i &lt; 5; i++)
                {

                        if (i == 0)
                        {
                                cout &lt;&lt; &quot;Geben Sie die 1. Ziffer der 1. Zahl ein: &quot;;
                                cin &gt;&gt; x;
                                if (x == 0 || x == 1 || x == 2 || x == 3 || x == 4 || x == 5 || x == 6 || x == 7 || x == 8 || x == 9  )
                                {

                                }
                                else
                                {
                                        i--;
                                        continue;
                                }

                        }
                        if (i == 1)
                        {
                                cout &lt;&lt; &quot;Geben Sie die 2. Ziffer der 1. Zahl ein: &quot;;
                                cin &gt;&gt; x1;
                                if (x1 == 0 || x1 == 1 || x1 == 2 || x1 == 3 || x1 == 4 || x1 == 5 || x1 == 6 || x1 == 7 || x1 == 8 || x1 == 9  )
                                {

                                }
                                else
                                {
                                        i--;
                                        continue;
                                }
                        }
                        if (i == 2)
                        {
                                cout &lt;&lt; &quot;Geben Sie die 1. Ziffer der 2. Zahl ein: &quot;;
                                cin &gt;&gt; y;
                                if (y == 0 || y == 1 || y == 2 || y == 3 || y == 4 || y == 5 || y == 6 || y == 7 || y == 8 || y == 9)
                                {

                                }
                                else
                                {
                                        i--;
                                        continue;
                                }
                        }
                        if (i == 3)
                        {
                                cout &lt;&lt; &quot;Geben Sie die 2. Ziffer der 1. Zahl ein: &quot;;
                                cin &gt;&gt; y1;
                                if (y1 == 0 || y1 == 1 || y1 == 2 || y1 == 3 || y1 == 4 || y1 == 5 || y1 == 6 || y1 == 7 || y1 == 8 || y1 == 9)
                                {

                                }
                                else
                                {
                                        i--;
                                        continue;
                                }
                        }
                        if (i==4)
                        {
                                cout &lt;&lt; &quot;Geben Sie die Rechenoperation ein (+ oder -) : &quot;;
                                cin &gt;&gt; z;
                                if (z == '+' || z == '-' )
                                {

                                }
                                else
                                {
                                        i--;
                                        continue;
                                }

                        }

                }

                return x,x1,y,y1,z;
        }
}
</code></pre>
<pre><code>#include &lt;iostream&gt;
#include &quot;gui.h&quot;
#include &quot;calc.h&quot;
using namespace std;

int main()
{

        int zahl1_wert1 =0;
        int zahl1_wert2=0;
        int zahl2_wert1=0;
        int zahl2_wert2=0;
        char a ;

        gui::eingabe(zahl1_wert1,zahl1_wert2,zahl2_wert1,zahl2_wert2,a);

        system(&quot;PAUSE&quot;);
        return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2477363</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2477363</guid><dc:creator><![CDATA[as1as]]></dc:creator><pubDate>Fri, 27 Nov 2015 19:09:58 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler bei Programmmodularisierung und Referenzparametern on Fri, 27 Nov 2015 21:06:31 GMT]]></title><description><![CDATA[<p>Ich weiss einfach nicht wie ich mein Ergebniss von meiner calculate Funktion nun in mein Hauptprogramm bekomme das ich es in meine printout funktion einbindnen kann. Meine Variable für das Ergebniss ist ja int ausgabe. Jedoch ist diese<br />
ja nur in meiner Funktion calc sichtbar. Ich habe nun versucht vllt durch den<br />
namespace irgendwie meine variable ausgabe in mein mainprogramm zu bekommen aber es gelingt mir einfach nicht):</p>
<pre><code>#include &lt;iostream&gt;
#include &quot;gui.h&quot;
#include &quot;calc.h&quot;
using namespace std;
using namespace gui;
using namespace calc;

int main()
{

	int zahl1_wert1 =0;
	int zahl1_wert2=0;
	int zahl2_wert1=0;
	int zahl2_wert2=0;
	char a ;

	eingabe(zahl1_wert1,zahl1_wert2,zahl2_wert1,zahl2_wert2,a);

	calculate(zahl1_wert1, zahl1_wert2, zahl2_wert1, zahl2_wert2, a);

	//gui::printout();

	system(&quot;PAUSE&quot;);
	return 0;
}
</code></pre>
<pre><code>#include &quot;calc.h&quot;

namespace calc
{
	int calculate(int x, int x1, int y, int y1, char z)
	{

		int zahl_eins_stelle1 = x * 10;
		int zahl_eins = x + x1;

		int zahl_zwei_stelle1 = y * 10;
		int zahl_zwei = y + y1;
		int ausgabe = 0;
		if (z == '+')
		{
			ausgabe = zahl_eins + zahl_zwei;
		}
		if (z =='-')
		{
			ausgabe = zahl_eins - zahl_zwei;
		}
		return ausgabe;

	}

}
</code></pre>
<pre><code>#include &quot;gui.h&quot;
#include &lt;iostream&gt;
using namespace std;

 namespace gui
{

	void printout(int)
	{

		//cout &lt;&lt; &quot;Das Ergebnis lautet: &quot; &lt;&lt; ;
	}
	int eingabe(int &amp;x, int &amp;x1, int &amp;y, int &amp;y1, char &amp;z)
	{
		int charwert = 0;

		for (int  i = 0; i &lt; 5; i++)
		{

			if (i == 0)
			{
				cout &lt;&lt; &quot;Geben Sie die 1. Ziffer der 1. Zahl ein: &quot;;
				cin &gt;&gt; x;
				if (x == 0 || x == 1 || x == 2 || x == 3 || x == 4 || x == 5 || x == 6 || x == 7 || x == 8 || x == 9  )
				{

				}
				else
				{
					i--;
					continue;
				}

			}
			if (i == 1)
			{
				cout &lt;&lt; &quot;Geben Sie die 2. Ziffer der 1. Zahl ein: &quot;;
				cin &gt;&gt; x1;
				if (x1 == 0 || x1 == 1 || x1 == 2 || x1 == 3 || x1 == 4 || x1 == 5 || x1 == 6 || x1 == 7 || x1 == 8 || x1 == 9  )
				{

				}
				else
				{
					i--;
					continue;
				}
			}
			if (i == 2)
			{
				cout &lt;&lt; &quot;Geben Sie die 1. Ziffer der 2. Zahl ein: &quot;;
				cin &gt;&gt; y;
				if (y == 0 || y == 1 || y == 2 || y == 3 || y == 4 || y == 5 || y == 6 || y == 7 || y == 8 || y == 9)
				{

				}
				else
				{
					i--;
					continue;
				}
			}
			if (i == 3)
			{
				cout &lt;&lt; &quot;Geben Sie die 2. Ziffer der 1. Zahl ein: &quot;;
				cin &gt;&gt; y1;
				if (y1 == 0 || y1 == 1 || y1 == 2 || y1 == 3 || y1 == 4 || y1 == 5 || y1 == 6 || y1 == 7 || y1 == 8 || y1 == 9)
				{

				}
				else
				{
					i--;
					continue;
				}
			}
			if (i==4)
			{
				cout &lt;&lt; &quot;Geben Sie die Rechenoperation ein (+ oder -) : &quot;;
				cin &gt;&gt; z;
				if (z == '+' || z == '-' )
				{

				}
				else
				{
					i--;
					continue;
				}

			}

		}

		return x,x1,y,y1,z;
	}
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2477373</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2477373</guid><dc:creator><![CDATA[as1as]]></dc:creator><pubDate>Fri, 27 Nov 2015 21:06:31 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler bei Programmmodularisierung und Referenzparametern on Fri, 27 Nov 2015 21:49:19 GMT]]></title><description><![CDATA[<p>as1as schrieb:</p>
<blockquote>
<pre><code>return x,x1,y,y1,z;
	}
}
</code></pre>
</blockquote>
<p>Achtung, Koma-Operator.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2477377</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2477377</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Fri, 27 Nov 2015 21:49:19 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler bei Programmmodularisierung und Referenzparametern on Fri, 27 Nov 2015 21:51:12 GMT]]></title><description><![CDATA[<p>volkard schrieb:</p>
<blockquote>
<p>as1as schrieb:</p>
<blockquote>
<pre><code>return x,x1,y,y1,z;
	}
}
</code></pre>
</blockquote>
<p>Achtung, Koma-Operator.</p>
</blockquote>
<p>Darf man das nicht so schreiben? Oder habe ich in der Reihenfolge etwas falsch gemacht?<br />
lg</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2477378</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2477378</guid><dc:creator><![CDATA[as1as]]></dc:creator><pubDate>Fri, 27 Nov 2015 21:51:12 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler bei Programmmodularisierung und Referenzparametern on Fri, 27 Nov 2015 21:52:49 GMT]]></title><description><![CDATA[<p>(eigentlich hab ich ein suchwort zum googeln eingeworfen.)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2477379</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2477379</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Fri, 27 Nov 2015 21:52:49 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler bei Programmmodularisierung und Referenzparametern on Sat, 28 Nov 2015 08:55:29 GMT]]></title><description><![CDATA[<p>FTFY: Komma-Operator.</p>
<p>Aber ins Koma kommt man bei dem Code auch <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><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/32505">@as1as</a>:</p>
<pre><code class="language-cpp">int ergebnis = calculate(zahl1_wert1, zahl1_wert2, zahl2_wert1, zahl2_wert2, a);

printout(ergebnis);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2477400</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2477400</guid><dc:creator><![CDATA[Th69]]></dc:creator><pubDate>Sat, 28 Nov 2015 08:55:29 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler bei Programmmodularisierung und Referenzparametern on Sat, 28 Nov 2015 16:48:02 GMT]]></title><description><![CDATA[<p>Danke für die helfenden Beiträge. Mein Programm läuft nun.<br />
Die einzige Sache die noch nicht läuft ist wenn man bei den vier Zahlabfragen einen Buchstaben eingibt.<br />
Ich habe mich ein wenig mit dem Kommaoperator befasst und denke es müsste nun dadran liegen, weil meine ersten vier Werte x,x1,y,y1 int Werte sind und keine char Werte. Daher kommt der Fehler. Jedoch verstehe ich nicht warum der Fehler auftritt. Meine if Abfrage sollte doch jeden char abfangen und mich sofort wieder zur erneuten Eingabe auffordern. Das hieße ja , man darf schon bei cin&gt;&gt; x keine<br />
Eingabe machen welche != Zahl ist. Ich wüsste nicht wie ich das kontrollieren könnte. Jemand ein Tipp?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2477433</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2477433</guid><dc:creator><![CDATA[as1as]]></dc:creator><pubDate>Sat, 28 Nov 2015 16:48:02 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler bei Programmmodularisierung und Referenzparametern on Sun, 29 Nov 2015 11:39:48 GMT]]></title><description><![CDATA[<p>Sobald bei cin im Stream ein Zeichen ist, welches nicht geparst werden kann (z.B. ein Buchstabe bei einem 'int'), dann wird der gesamte Stream in den Fehlerstatus gesetzt und du müßtest diesen wieder zurücksetzen. Such mal nach &quot;cin.clear()&quot; hier im Forum.</p>
<p>Ich frage mich aber schon die ganze Zeit, warum du genau 2 Stellen abfragst, anstatt einfach jede mögliche Zahl einliest, d.h. nur ein &quot;cin &lt;&lt; x;&quot; benutzt (und die große Schleife ist auch überflüssig):</p>
<pre><code class="language-cpp">int eingabe(int &amp;x, int &amp;y, char &amp;op)
{
  cout &lt;&lt; &quot;Geben Sie die 1. Zahl ein: &quot;;
  cin &gt;&gt; x;

  cout &lt;&lt; &quot;Geben Sie die Rechenoperation ein (+ oder -) : &quot;;
  cin &gt;&gt; op;

  cout &lt;&lt; &quot;Geben Sie die 2. Zahl ein: &quot;;
  cin &gt;&gt; y;
}
</code></pre>
<p>Wenn du die Neueingabe der einzelnen Zahlen oder des Rechenzeichens möchtest, dann packe jeweils nur um &quot;cout / cin&quot; eine Schleife, z.B.</p>
<pre><code class="language-cpp">do
{
  cout &lt;&lt; &quot;Geben Sie die 1. Zahl ein: &quot;;
  cin.clear();
  cin.ignore(numeric_limits&lt;streamsize&gt;::max(), '\n');  // Letzte Eingabe ignorieren
  cin &gt;&gt; x;
} while(!cin); // Fehlerstatus abfragen
</code></pre>
<p>Am besten die beiden Funktionen dann in eine eigene Funktion packen:</p>
<pre><code class="language-cpp">void clearbuffer()
{
  cin.clear();
  cin.ignore(numeric_limits&lt;streamsize&gt;::max(), '\n');  // Letzte Eingabe ignorieren
}
</code></pre>
<p>und diese dann oben aufrufen (und noch &quot;#include &lt;limits&gt;&quot; einfügen).</p>
<p>Edit:<br />
Und obwohl du soweit noch nicht bist (d.h. dies ist eher für die anderen Leser interessant), könnte man die ganze Funktion dann als Template realisieren:</p>
<pre><code class="language-cpp">template&lt;T&gt; void input(const char *text, T&amp; t)
{
  do
  {
    cout &lt;&lt; text;
    clearbuffer();
    cin &gt;&gt; t;
  } while(!cin); // Fehlerstatus abfragen
]
</code></pre>
<p>Und dann einfach so aufrufen:</p>
<pre><code class="language-cpp">int x;
input(&quot;Geben Sie die 1. Zahl ein: &quot;, x);
</code></pre>
<p>Alternativ den eingegeben Wert als Rückgabewert, aber dann muß der Datentyp explizit angegeben werden (da der Compiler ihn nicht mehr aus den Parametern ermitteln kann):</p>
<pre><code class="language-cpp">int x = input&lt;int&gt;(&quot;Geben Sie die 1. Zahl ein: &quot;);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2477499</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2477499</guid><dc:creator><![CDATA[Th69]]></dc:creator><pubDate>Sun, 29 Nov 2015 11:39:48 GMT</pubDate></item></channel></rss>