<?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[Falsche Ausgabe auserhalb der Schleife]]></title><description><![CDATA[<p>Abend liebe c++ Freunde,</p>
<p>Ich hab hier gerade ein sehr komisches Problem,<br />
Dieser Programmauszug ließt Messwerte in eine Tabelle ein und gibt die alle aus.</p>
<p>Da ich diese Werte-Tabelle auch später noch brauche habe ich ausserhalb einmal ausgeben, doch es kommt dabei ein anderer Wert raus ( siehe Bild)</p>
<p><a href="http://img4.imagebanana.com/img/jn50arh3/11.jpg" rel="nofollow">http://img4.imagebanana.com/img/jn50arh3/11.jpg</a></p>
<p>Worin liegt mein Fehler??</p>
<pre><code class="language-cpp">....
ifstream input;
input.open(inFile.c_str());

if(!input)
	cerr &lt;&lt; &quot;FEHLER: Datei öffnen fehlgeschlagen&quot;;

for (int j = 0; j &lt; 20; j++)
	{
		input &gt;&gt; tabelle[1][j];
		input &gt;&gt; tabelle[2][j];
		cout &lt;&lt; tabelle[1][j] &lt;&lt; '\t' &lt;&lt; tabelle[2][j] &lt;&lt; endl;
	}

cout &lt;&lt; tabelle[1][0] &lt;&lt; '\t' &lt;&lt; tabelle[2][0] &lt;&lt; endl;
...
</code></pre>
<p>vielen dank<br />
mfg fraggelfragger</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/202129/falsche-ausgabe-auserhalb-der-schleife</link><generator>RSS for Node</generator><lastBuildDate>Tue, 06 Oct 2026 15:05:59 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/202129.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 07 Jan 2008 21:01:00 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Falsche Ausgabe auserhalb der Schleife on Mon, 07 Jan 2008 21:14:58 GMT]]></title><description><![CDATA[<p>Abend liebe c++ Freunde,</p>
<p>Ich hab hier gerade ein sehr komisches Problem,<br />
Dieser Programmauszug ließt Messwerte in eine Tabelle ein und gibt die alle aus.</p>
<p>Da ich diese Werte-Tabelle auch später noch brauche habe ich ausserhalb einmal ausgeben, doch es kommt dabei ein anderer Wert raus ( siehe Bild)</p>
<p><a href="http://img4.imagebanana.com/img/jn50arh3/11.jpg" rel="nofollow">http://img4.imagebanana.com/img/jn50arh3/11.jpg</a></p>
<p>Worin liegt mein Fehler??</p>
<pre><code class="language-cpp">....
ifstream input;
input.open(inFile.c_str());

if(!input)
	cerr &lt;&lt; &quot;FEHLER: Datei öffnen fehlgeschlagen&quot;;

for (int j = 0; j &lt; 20; j++)
	{
		input &gt;&gt; tabelle[1][j];
		input &gt;&gt; tabelle[2][j];
		cout &lt;&lt; tabelle[1][j] &lt;&lt; '\t' &lt;&lt; tabelle[2][j] &lt;&lt; endl;
	}

cout &lt;&lt; tabelle[1][0] &lt;&lt; '\t' &lt;&lt; tabelle[2][0] &lt;&lt; endl;
...
</code></pre>
<p>vielen dank<br />
mfg fraggelfragger</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1432707</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1432707</guid><dc:creator><![CDATA[fraggelfragger]]></dc:creator><pubDate>Mon, 07 Jan 2008 21:14:58 GMT</pubDate></item><item><title><![CDATA[Reply to Falsche Ausgabe auserhalb der Schleife on Mon, 07 Jan 2008 21:29:24 GMT]]></title><description><![CDATA[<p>kannst du mal einmal zeigen wie du das array definierst?<br />
Kann es sein, dass du nicht für 20Elemente reserviert hast?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1432729</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1432729</guid><dc:creator><![CDATA[Andreas_LL]]></dc:creator><pubDate>Mon, 07 Jan 2008 21:29:24 GMT</pubDate></item><item><title><![CDATA[Reply to Falsche Ausgabe auserhalb der Schleife on Mon, 07 Jan 2008 21:41:41 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">//a) Definieren der 20*2 Matrix
	double tabelle[20][2];
</code></pre>
<p>ich poste einfach mal den ganzen Code:<br />
(selbstverständlich werde ich später das in Unterfunktion bzw. klasse ummformen also bitte nicht davon stören lassen das ich alles in main Methode habe)</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;string&gt;

using namespace std;

int main() 
{

	//a) Definieren der 20*2 Matrix
	double tabelle[20][2];

	//b) Einlesen der Werte
	string inFile = &quot;messungen.txt&quot;;
	string outFile = &quot;auswertung.txt&quot;;

	ifstream input;
	input.open(inFile.c_str());

	if(!input)
		cerr &lt;&lt; &quot;FEHLER: Datei öffnen fehlgeschlagen&quot;;

	for (int j = 0; j &lt; 20; j++)
		{
			input &gt;&gt; tabelle[1][j];
			input &gt;&gt; tabelle[2][j];
			cout &lt;&lt; tabelle[1][j] &lt;&lt; '\t' &lt;&lt; tabelle[2][j] &lt;&lt; endl;
		}

	cout &lt;&lt; tabelle[1][0] &lt;&lt; '\t' &lt;&lt; tabelle[2][1] &lt;&lt; endl;

	//Ausgleichsgerade
	double Sx  =0;
	double Sy  =0;
	double Sxx =0;
	double Sxy =0;
	int n     =20;

	for (int k = 0; k &lt; 20; k++)
		{
			Sx += tabelle[1][k];
			Sy += tabelle[2][k];
			Sxx += tabelle[1][k]* tabelle[1][k];
			Sxy += tabelle[1][k] * tabelle[2][k];
		}

	double a = (n * Sxy - Sx*Sy) / (n*Sxx - Sx * Sx);
	double b = (Sy - a* Sx) / n;

	// d) delta_i berechnen
	double delta_i[20];

	for(int l = 0;l &lt; 20; l++)
		delta_i[l] = (a * tabelle[1][l] + b ) - tabelle[2][l];

	double fqs = 0;

	for(int m = 0;m &lt; 20; m++)
		fqs += delta_i[m] * delta_i[m];

	//f) Ausgeben der Rechnungen
	ofstream output;
	output.open(outFile.c_str());

	if(!output)
		cerr &lt;&lt; &quot;FEHLER: Datei öffnen fehlgeschlagen&quot;; 

	for (int n = 0; n &lt; 20; n++)
		output &lt;&lt; tabelle[1][n] &lt;&lt; '\t' &lt;&lt; tabelle[2][n] &lt;&lt; '\t' &lt;&lt; delta_i[n] &lt;&lt; endl;

	output &lt;&lt; &quot;\nDer Wert von a : &quot; &lt;&lt; a &lt;&lt; endl;
	output &lt;&lt; &quot;Der Wert von b : &quot; &lt;&lt; b &lt;&lt; endl;
	output &lt;&lt; &quot;Der Wert von fqs : &quot; &lt;&lt; fqs &lt;&lt; endl;

	cin.get();

	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1432744</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1432744</guid><dc:creator><![CDATA[fraggelfragger]]></dc:creator><pubDate>Mon, 07 Jan 2008 21:41:41 GMT</pubDate></item><item><title><![CDATA[Reply to Falsche Ausgabe auserhalb der Schleife on Mon, 07 Jan 2008 22:05:13 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">for (int j = 0; j &lt; 20; j++) 
        { 
            input &gt;&gt; tabelle[1][j]; 
            input &gt;&gt; tabelle[2][j]; 
            cout &lt;&lt; tabelle[1][j] &lt;&lt; '\t' &lt;&lt; tabelle[2][j] &lt;&lt; endl; 
        }
</code></pre>
<p>Würde ja funktionieren wenn du dein Array als double tabelle[2][20]; angeölegt hättest.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1432759</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1432759</guid><dc:creator><![CDATA[darthdespotism]]></dc:creator><pubDate>Mon, 07 Jan 2008 22:05:13 GMT</pubDate></item><item><title><![CDATA[Reply to Falsche Ausgabe auserhalb der Schleife on Mon, 07 Jan 2008 22:14:47 GMT]]></title><description><![CDATA[<p>super! vielen dank ( ich schäme mich, das ist echt ein blöder Fehler)<br />
neija sagen wirs mal so bin weligstens nicht auf den fence post error reingefallen <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>Wieso zeigt der aber dann in der Schleife das richtige an??<br />
Wenn er es da auch nicht getan hätte, wäre ich vllt. auf die Vermutung gekommen das das Array falsch ist.</p>
<p>mfg fraggelfragger</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1432763</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1432763</guid><dc:creator><![CDATA[fraggelfragger]]></dc:creator><pubDate>Mon, 07 Jan 2008 22:14:47 GMT</pubDate></item><item><title><![CDATA[Reply to Falsche Ausgabe auserhalb der Schleife on Mon, 07 Jan 2008 22:28:39 GMT]]></title><description><![CDATA[<p>Zugriff auf nicht allokierten Speicher führt zu <strong>undefiniertem</strong> Verhalten. Das Programm kann alles denkbare machen, incl. das, was du erwartest.</p>
<p>Möglicherweise gehört dir der Speicher und steht für andere Variablen zur Verfügung. Daher kannst du den frisch eingelesenen Wert korrekt ausgeben. Später schreibst du vll in die entsprechenden Variablen und was herauskommt ist nur noch Müll.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1432773</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1432773</guid><dc:creator><![CDATA[darthdespotism]]></dc:creator><pubDate>Mon, 07 Jan 2008 22:28:39 GMT</pubDate></item><item><title><![CDATA[Reply to Falsche Ausgabe auserhalb der Schleife on Tue, 08 Jan 2008 11:34:24 GMT]]></title><description><![CDATA[<p>Außerdem fangen die Indizes bei 0 an, d.h. du mußt 0 und 1 (nicht 1 und 2) als Index benutzen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1432942</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1432942</guid><dc:creator><![CDATA[Th]]></dc:creator><pubDate>Tue, 08 Jan 2008 11:34:24 GMT</pubDate></item></channel></rss>