<?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[Arrays bekommen seltsame Werte]]></title><description><![CDATA[<p>Hallo Leute<br />
ich bin grad dabei ein Programm zur Umrechnung von Schulnoten in das Oberstufen-Punktesystem zu schreiben.<br />
aber wenn ich das ganze ausführe bekomme ich erst diese Fehlermeldung:<br />
&quot;Runtime-Check Failture #3 - The variable 'a' is being used without being initialized.&quot;</p>
<p>Wenn ich das ignoriere wird das Programm weiter ausgeführt und die a-arrays bekommen komische Werte, wie 858993475.<br />
Das kann ich irgendwie nicht ganz nachvollziehen...</p>
<p>Hier mein Code:</p>
<pre><code class="language-cpp">// Programm zur Noten-Punkteberechnung

#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;conio.h&gt;
using namespace std;

int main()
{
	int anzNot = 0;
	int g = 0;				//NotPkt
	string z;				//Note String
	int x = 0;				//Laufzähler1
	int y = 0;				//Laufzähler2
	int a[10];				//Noten einzeln

	system(&quot;CLS&quot;);
	cout &lt;&lt; &quot;Bitte gib die Anzahl der einzugebenen Noten ein. Es können nicht mehr als 10 Noten eingegeben werden.&quot; &lt;&lt; endl;
	cin &gt;&gt; anzNot;

	while (x &lt; anzNot)
	{
		cout &lt;&lt; &quot;Gib die Note vom &quot; &lt;&lt; x + 1 &lt;&lt; &quot;. Fach ein.&quot; &lt;&lt; endl;
		cin &gt;&gt; z;

							//Umrechnung in Punkte
		if (z == &quot;1+&quot;)
		{	g += 15;	}
		if (z == &quot;1&quot;)
		{	g += 14;	}
		if (z == &quot;1-&quot;)
		{	g += 13;	}
		if (z == &quot;2+&quot;)
		{	g += 12;	}
		if (z == &quot;2&quot;)
		{	g += 11;	}
		if (z == &quot;2-&quot;)
		{	g += 10;	}
		if (z == &quot;3+&quot;)
		{	g += 9;	}
		if (z == &quot;3&quot;)
		{	g += 8;	}
		if (z == &quot;3-&quot;)
		{	g += 7;	}
		if (z == &quot;4+&quot;)
		{	g += 6;	}
		if (z == &quot;4&quot;)
		{	g += 5;	}
		if (z == &quot;4-&quot;)
		{	g += 4;	}
		if (z == &quot;5+&quot;)
		{	g += 3;	}
		if (z == &quot;5&quot;)
		{	g += 2;	}
		if (z == &quot;5-&quot;)
		{	g += 1;	}
		if (z == &quot;6&quot;)
		{	g += 0;	}
		x++;
							//Zuordnung zu Arrays
		switch(x)
		{
		case 0: a[0] = g;
			break;
		case 1: a[1] = g - a[0];
			break;
		case 2: a[2] = g - a[1];
			break;
		case 3: a[3] = g - a[2];
			break;
		case 4: a[4] = g - a[3];
			break;
		case 5: a[5] = g - a[4];
			break;
		case 6: a[6] = g - a[5];
			break;
		case 7: a[7] = g - a[6];
			break;
		case 8: a[8] = g - a[7];
			break;
		case 9: a[9] = g - a[8];
		}
	}
						//Ausgabe
	cout &lt;&lt; &quot;Deine Noten in Punkte umgerechnet sind: &quot;;
	while (y &lt; x)
	{
		cout &lt;&lt; a[x] &lt;&lt; &quot;, &quot;;
		y++;
	}

	getch();
	return 0;
}
</code></pre>
<p>Ich bin für jede Hilfe Dankbar<br />
JanK411</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/298202/arrays-bekommen-seltsame-werte</link><generator>RSS for Node</generator><lastBuildDate>Thu, 13 Aug 2026 22:41:09 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/298202.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 15 Jan 2012 18:12:32 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Arrays bekommen seltsame Werte on Sun, 15 Jan 2012 18:12:32 GMT]]></title><description><![CDATA[<p>Hallo Leute<br />
ich bin grad dabei ein Programm zur Umrechnung von Schulnoten in das Oberstufen-Punktesystem zu schreiben.<br />
aber wenn ich das ganze ausführe bekomme ich erst diese Fehlermeldung:<br />
&quot;Runtime-Check Failture #3 - The variable 'a' is being used without being initialized.&quot;</p>
<p>Wenn ich das ignoriere wird das Programm weiter ausgeführt und die a-arrays bekommen komische Werte, wie 858993475.<br />
Das kann ich irgendwie nicht ganz nachvollziehen...</p>
<p>Hier mein Code:</p>
<pre><code class="language-cpp">// Programm zur Noten-Punkteberechnung

#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;conio.h&gt;
using namespace std;

int main()
{
	int anzNot = 0;
	int g = 0;				//NotPkt
	string z;				//Note String
	int x = 0;				//Laufzähler1
	int y = 0;				//Laufzähler2
	int a[10];				//Noten einzeln

	system(&quot;CLS&quot;);
	cout &lt;&lt; &quot;Bitte gib die Anzahl der einzugebenen Noten ein. Es können nicht mehr als 10 Noten eingegeben werden.&quot; &lt;&lt; endl;
	cin &gt;&gt; anzNot;

	while (x &lt; anzNot)
	{
		cout &lt;&lt; &quot;Gib die Note vom &quot; &lt;&lt; x + 1 &lt;&lt; &quot;. Fach ein.&quot; &lt;&lt; endl;
		cin &gt;&gt; z;

							//Umrechnung in Punkte
		if (z == &quot;1+&quot;)
		{	g += 15;	}
		if (z == &quot;1&quot;)
		{	g += 14;	}
		if (z == &quot;1-&quot;)
		{	g += 13;	}
		if (z == &quot;2+&quot;)
		{	g += 12;	}
		if (z == &quot;2&quot;)
		{	g += 11;	}
		if (z == &quot;2-&quot;)
		{	g += 10;	}
		if (z == &quot;3+&quot;)
		{	g += 9;	}
		if (z == &quot;3&quot;)
		{	g += 8;	}
		if (z == &quot;3-&quot;)
		{	g += 7;	}
		if (z == &quot;4+&quot;)
		{	g += 6;	}
		if (z == &quot;4&quot;)
		{	g += 5;	}
		if (z == &quot;4-&quot;)
		{	g += 4;	}
		if (z == &quot;5+&quot;)
		{	g += 3;	}
		if (z == &quot;5&quot;)
		{	g += 2;	}
		if (z == &quot;5-&quot;)
		{	g += 1;	}
		if (z == &quot;6&quot;)
		{	g += 0;	}
		x++;
							//Zuordnung zu Arrays
		switch(x)
		{
		case 0: a[0] = g;
			break;
		case 1: a[1] = g - a[0];
			break;
		case 2: a[2] = g - a[1];
			break;
		case 3: a[3] = g - a[2];
			break;
		case 4: a[4] = g - a[3];
			break;
		case 5: a[5] = g - a[4];
			break;
		case 6: a[6] = g - a[5];
			break;
		case 7: a[7] = g - a[6];
			break;
		case 8: a[8] = g - a[7];
			break;
		case 9: a[9] = g - a[8];
		}
	}
						//Ausgabe
	cout &lt;&lt; &quot;Deine Noten in Punkte umgerechnet sind: &quot;;
	while (y &lt; x)
	{
		cout &lt;&lt; a[x] &lt;&lt; &quot;, &quot;;
		y++;
	}

	getch();
	return 0;
}
</code></pre>
<p>Ich bin für jede Hilfe Dankbar<br />
JanK411</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2168443</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2168443</guid><dc:creator><![CDATA[JanK411]]></dc:creator><pubDate>Sun, 15 Jan 2012 18:12:32 GMT</pubDate></item><item><title><![CDATA[Reply to Arrays bekommen seltsame Werte on Sun, 15 Jan 2012 18:28:31 GMT]]></title><description><![CDATA[<p>Wenn du das erste Mal zum switch(x) kommst, dann hat x schon den Wert 1. Und dann wird a[0] benutzt, welches noch uninitialisiert ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2168450</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2168450</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Sun, 15 Jan 2012 18:28:31 GMT</pubDate></item><item><title><![CDATA[Reply to Arrays bekommen seltsame Werte on Sun, 15 Jan 2012 18:29:05 GMT]]></title><description><![CDATA[<p>Ich denke das Problem liegt in Zeile 59. Dort ist bereits ein x++. Deswegen ist im switch-statemente nie x = 0, wodruch a[0] nie initialisiert wird. Deswegen hast du nachher ein nicht initialisiertes array a.</p>
<p>Wahrscheinlich muss das x++ nach dem switch-statement kommen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2168451</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2168451</guid><dc:creator><![CDATA[icarus2]]></dc:creator><pubDate>Sun, 15 Jan 2012 18:29:05 GMT</pubDate></item><item><title><![CDATA[Reply to Arrays bekommen seltsame Werte on Sun, 15 Jan 2012 18:47:31 GMT]]></title><description><![CDATA[<p>Das will ich mir garnicht ansehen. Schleifen wär'n nicht schlecht, 's sag ich dir jetzt nur so.</p>
<p>Umgestaltung! <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="😃"
    /> <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="🙄"
    /> hehe<br />
Ich hätt's so gemacht:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;string&gt;

int main()
{
    for(std::string note;;)//Altes Notensystem string
    {
        std::cout &lt;&lt; &quot;Bitte Note eingeben:\n&quot;;
        std::getline(std::cin, note);//Alte Note einlesen

        if(note.length() &gt; 2 //Länger als zwei Zeichen ist eine Note eigentlich nicht
        || !isdigit(note.at(0)) //Das erste ist eine Zahl...
        || note.at(0) &gt; '6' //...die nicht größer als 6...
        || note.at(0) &lt; '1'   //Und nicht kleiner als 1 ist
        ||   (note.length() &gt; 1 
           &amp;&amp; note.at(1) != '-' //Es gibt nur das - ...
           &amp;&amp; note.at(1) != '+'))//...oder + danach, sonst nichts
        {
            std::cout &lt;&lt; &quot;Ungültige Note eingegeben! Bitte erneut versuchen.\n&quot;;//Dann wird ein Fehler ausgegeben
            continue;
        }

        size_t onote(14);///Standardwert: 1, neue Variable die die Note im Neuen System hält
        if(note.length() &gt; 1)//Wenn der string größer als 1 Zeichen ist, ist ein + oder - in der Note
            onote -= ((note.at(1) == '-')? 1 : -1);//Dann wird die Note einen Punkt besser oder schlechter
        onote -= (note.at(0) - '0' - 1) * 3;//Die Hauptnote (also bei 3- die 3) wird mal 3 genommen. Anschließend wird ein Notenpunkt abgezogen.

        std::cout &lt;&lt; &quot;Die Note im Oberstufensystem:\n&quot; &lt;&lt; onote &lt;&lt; &quot;\n\n&quot;;//Ausgabe der fertigen Note
    }
}
</code></pre>
<p>Edit: Klar kann man sich dafür eine Funktion schreiben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2168453</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2168453</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Sun, 15 Jan 2012 18:47:31 GMT</pubDate></item><item><title><![CDATA[Reply to Arrays bekommen seltsame Werte on Sun, 15 Jan 2012 18:48:36 GMT]]></title><description><![CDATA[<p>Danke!<br />
Damit ist die nicht initialisierte Variable behoben.<br />
aber ich hab immer noch die komischen Werte...<br />
@Hacker: ich bin noch ein kläglicher Anfänger, müsst ihr wissen... aber ich denke mal, dass selbst wenn ich das ganze so mache, die Werte für a immer noch so seltsam bleiben...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2168455</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2168455</guid><dc:creator><![CDATA[JanK411]]></dc:creator><pubDate>Sun, 15 Jan 2012 18:48:36 GMT</pubDate></item><item><title><![CDATA[Reply to Arrays bekommen seltsame Werte on Sun, 15 Jan 2012 18:48:49 GMT]]></title><description><![CDATA[<p>Du solltest einmal lernen einen Debugger zu benuetzen. Dann wuerdest du sehen, dass das Array korrekte Werte enthaelt aber die Ausgabe falsch ist:</p>
<pre><code class="language-cpp">cout &lt;&lt; &quot;Deine Noten in Punkte umgerechnet sind: &quot;; 
    while (y &lt; x) 
    { 
        cout &lt;&lt; a[y] &lt;&lt; &quot;, &quot;; // a[y] und nicht a[x] wie in deinem Code
        y++; 
    }
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2168456</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2168456</guid><dc:creator><![CDATA[icarus2]]></dc:creator><pubDate>Sun, 15 Jan 2012 18:48:49 GMT</pubDate></item><item><title><![CDATA[Reply to Arrays bekommen seltsame Werte on Sun, 15 Jan 2012 18:58:46 GMT]]></title><description><![CDATA[<p>Oh verdammt...<br />
hinsehen will gelernt sein!<br />
was genau ist denn mit &quot;debugger&quot; gemeint?<br />
ich benutze visual studio 2010 und &quot;debugge&quot; vor jedem Ausführen...</p>
<p>aber wenn ich das Programm jetzt ausführe sind die Werte immer noch nicht ganz richtig.<br />
Ich gebe 3 Noten ein: 1+, 2- und 3.<br />
dann bekomme ich die Werte 15, 10 und 23.<br />
Der Letzte davon kann ja eigentlich auch nicht stimmen.<br />
Wenn ich das ganze mit vier Noten mache, genauso usw... (alle Werte ab dem 3. sind falsch)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2168457</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2168457</guid><dc:creator><![CDATA[JanK411]]></dc:creator><pubDate>Sun, 15 Jan 2012 18:58:46 GMT</pubDate></item><item><title><![CDATA[Reply to Arrays bekommen seltsame Werte on Mon, 16 Jan 2012 02:01:55 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;cassert&gt;
#include &lt;string&gt;

std::string note_von_punkten(unsigned punkte)
{
  assert(punkte &lt;= 15);

  int note = 6- (punkte+2)/3;
  bool plus = punkte%3 == 0;
  bool minus = punkte%3 == 1;

  std::string ret_val(2, '\0');
  ret_val[0] = '0' + static_cast&lt;char&gt;(note);
  if(plus)       ret_val[1] = '+';
  else if(minus) ret_val[1] = '-';

  return ret_val;
}

#include &lt;iostream&gt;
#include &lt;limits&gt;

int main()
{
  unsigned punkte = 20;
  do
  {
    std::cin &gt;&gt; punkte;
    std::cin.ignore(std::numeric_limits&lt;std::streamsize&gt;::max(), '\n');
    std::cin.clear();
  } while(punkte &gt; 15);

  std::cout &lt;&lt; &quot; == &quot; &lt;&lt; note_von_punkten(punkte) &lt;&lt; std::endl;
}
</code></pre>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2168563</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2168563</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Mon, 16 Jan 2012 02:01:55 GMT</pubDate></item></channel></rss>