<?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[Rechnung mit Array]]></title><description><![CDATA[<p>Hallo liebe community,<br />
warum funktioniert der Code nicht?</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;  
using namespace std;

int main(1) 
{ 
	int a[50];
	int quersumme;

	cout &lt;&lt; 'Geben Sie eine vierstellige Zahl ein: '&lt;&lt; endl;
	cin &gt;&gt; a;
	quersumme = a[0] + a[1] + a[2] + a[3];
	cout &lt;&lt; 'Quersumme: ' &lt;&lt; quersumme &lt;&lt; flush;
}
</code></pre>
<p>Fehler:</p>
<pre><code>1&gt;------ Erstellen gestartet: Projekt: Test, Konfiguration: Debug Win32 ------
1&gt;Kompilieren...
1&gt;first.cpp
1&gt;c:\users\frank\desktop\c++\test\test\first.cpp(5) : error C2448: 'main': Funktionsstil-Initialisierung scheint eine Funktionsdefinition zu sein
1&gt;c:\users\frank\desktop\c++\test\test\first.cpp(9) : error C2015: Zu viele Zeichen in der Konstante
1&gt;c:\users\frank\desktop\c++\test\test\first.cpp(12) : error C2015: Zu viele Zeichen in der Konstante
1&gt;Das Buildprotokoll wurde unter &quot;file://c:\Users\frank\Desktop\C++\Test\Test\Debug\BuildLog.htm&quot; gespeichert.
1&gt;Test - 3 Fehler, 0 Warnung(en)
========== Erstellen: 0 erfolgreich, Fehler bei 1, 0 aktuell, 0 übersprungen ==========
</code></pre>
<p>Aufgabenstellung aus meinen Tutorial:<br />
Entwickeln Sie eine C++-Anwendung, die den Anwender zur Eingabe einer vierstelligen Zahl auffordert. Das Programm soll daraufhin die Quersumme der vierstelligen Zahl errechnen und das Ergebnis dann auf den Bildschirm ausgeben. Hinweis: Je nach Lösungsansatz benötigen Sie wie in Aufgabe 1 die Funktion atoi() zum Umrechnen von Zahlen innerhalb eines Arrays vom Typ char in Werte vom Typ int.</p>
<p>Wie in der Aufgabenstellung erwähnt habe ich es auch schon mit dem Typ char versucht, aber dies ist glaube ich nochmehr in die Hose gegangen.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;  
using namespace std;

int main(1) 
{ 
	char a[5];
	char quersumme;

	cout &lt;&lt; 'Geben Sie eine vierstellige Zahl ein: '&lt;&lt; endl;
	cin &gt;&gt; a;
	atoi(quersumme) = atoi(a[0]) + atoi(a[1]) + atoi(a[2]) + atoi(a[3]);
	cout &lt;&lt; 'Quersumme: ' &lt;&lt; static_cast&lt;int&gt;(quersumme) &lt;&lt; flush;

}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/218408/rechnung-mit-array</link><generator>RSS for Node</generator><lastBuildDate>Fri, 09 Oct 2026 03:03:53 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/218408.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 20 Jul 2008 16:51:30 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Rechnung mit Array on Sun, 20 Jul 2008 16:51:30 GMT]]></title><description><![CDATA[<p>Hallo liebe community,<br />
warum funktioniert der Code nicht?</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;  
using namespace std;

int main(1) 
{ 
	int a[50];
	int quersumme;

	cout &lt;&lt; 'Geben Sie eine vierstellige Zahl ein: '&lt;&lt; endl;
	cin &gt;&gt; a;
	quersumme = a[0] + a[1] + a[2] + a[3];
	cout &lt;&lt; 'Quersumme: ' &lt;&lt; quersumme &lt;&lt; flush;
}
</code></pre>
<p>Fehler:</p>
<pre><code>1&gt;------ Erstellen gestartet: Projekt: Test, Konfiguration: Debug Win32 ------
1&gt;Kompilieren...
1&gt;first.cpp
1&gt;c:\users\frank\desktop\c++\test\test\first.cpp(5) : error C2448: 'main': Funktionsstil-Initialisierung scheint eine Funktionsdefinition zu sein
1&gt;c:\users\frank\desktop\c++\test\test\first.cpp(9) : error C2015: Zu viele Zeichen in der Konstante
1&gt;c:\users\frank\desktop\c++\test\test\first.cpp(12) : error C2015: Zu viele Zeichen in der Konstante
1&gt;Das Buildprotokoll wurde unter &quot;file://c:\Users\frank\Desktop\C++\Test\Test\Debug\BuildLog.htm&quot; gespeichert.
1&gt;Test - 3 Fehler, 0 Warnung(en)
========== Erstellen: 0 erfolgreich, Fehler bei 1, 0 aktuell, 0 übersprungen ==========
</code></pre>
<p>Aufgabenstellung aus meinen Tutorial:<br />
Entwickeln Sie eine C++-Anwendung, die den Anwender zur Eingabe einer vierstelligen Zahl auffordert. Das Programm soll daraufhin die Quersumme der vierstelligen Zahl errechnen und das Ergebnis dann auf den Bildschirm ausgeben. Hinweis: Je nach Lösungsansatz benötigen Sie wie in Aufgabe 1 die Funktion atoi() zum Umrechnen von Zahlen innerhalb eines Arrays vom Typ char in Werte vom Typ int.</p>
<p>Wie in der Aufgabenstellung erwähnt habe ich es auch schon mit dem Typ char versucht, aber dies ist glaube ich nochmehr in die Hose gegangen.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;  
using namespace std;

int main(1) 
{ 
	char a[5];
	char quersumme;

	cout &lt;&lt; 'Geben Sie eine vierstellige Zahl ein: '&lt;&lt; endl;
	cin &gt;&gt; a;
	atoi(quersumme) = atoi(a[0]) + atoi(a[1]) + atoi(a[2]) + atoi(a[3]);
	cout &lt;&lt; 'Quersumme: ' &lt;&lt; static_cast&lt;int&gt;(quersumme) &lt;&lt; flush;

}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1550327</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1550327</guid><dc:creator><![CDATA[Frankstyles]]></dc:creator><pubDate>Sun, 20 Jul 2008 16:51:30 GMT</pubDate></item><item><title><![CDATA[Reply to Rechnung mit Array on Sun, 20 Jul 2008 16:59:04 GMT]]></title><description><![CDATA[<p>int main(1)<br />
Was hat denn die 1 dadrin verloren?</p>
<p>Verwende bei den Zeichenketten &quot; statt '</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1550331</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1550331</guid><dc:creator><![CDATA[cler]]></dc:creator><pubDate>Sun, 20 Jul 2008 16:59:04 GMT</pubDate></item><item><title><![CDATA[Reply to Rechnung mit Array on Sun, 20 Jul 2008 17:10:03 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/30103">@cler</a> ja das auch</p>
<p>Das Problem ist dass die vierstelliege Zahl nicht automatisch geteilt wird.<br />
Das heißt die &quot;ganze&quot; Zahl wird im array im Index 0 gespeichert</p>
<pre><code class="language-cpp">{code}

cin &gt;&gt; a[0];  // Bsp 1000

{code}

cout &lt;&lt; &quot;a[0] : &quot; &lt;&lt; a[0] &lt;&lt; endl;  // Ausgabe : 1000

{code}
</code></pre>
<p>Ich persönlich hab jetzt leider keine Ahnung wie man dein Problem jetzt genau löst tut mir leid <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
<p>lg c4f</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1550341</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1550341</guid><dc:creator><![CDATA[c4f]]></dc:creator><pubDate>Sun, 20 Jul 2008 17:10:03 GMT</pubDate></item><item><title><![CDATA[Reply to Rechnung mit Array on Sun, 20 Jul 2008 17:45:54 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;iostream&gt;  
using namespace std;

int main() // die 1 weg
{ 
	char a[5];
	int quersumme; // Quersumme ist ne Zahl, kein Buchstabe

	cout &lt;&lt; 'Geben Sie eine vierstellige Zahl ein: '&lt;&lt; endl;
	cin &gt;&gt; a;
	quersumme = atoi(a[0]) + atoi(a[1]) + atoi(a[2]) + atoi(a[3]); // s.o.
	cout &lt;&lt; 'Quersumme: ' &lt;&lt; quersumme &lt;&lt; flush; // s.o.
}
</code></pre>
<p>In C++ geht man da über String Streams. Ach ja, dein Code ist, mit Ausnahme des cout und cin Objektes, eher C Code als C++.<br />
Damit du mal ein bisschen siehst, wie C++ Code aussehen kann:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;sstream&gt; // std::istringstream
#include &lt;numeric&gt; // std::accumulate

int ToInt(char c)
{
	std::istringstream stream(std::string(1, c));
	int result;
	stream &gt;&gt; result;
	return result;
}

int sum_digits(int result, char digit)
{
	return result + ToInt(digit);
}

int main()
{
	std::cout &lt;&lt; &quot;Geben sie eine vier-stellige Zahl ein: &quot; &lt;&lt; std::endl;
	char digits[5];
	std::cin.getline(digits, 5);
	std::cout &lt;&lt; &quot;Quersumme: &quot; &lt;&lt; 
		std::accumulate(digits, digits + 4, 0, sum_digits) &lt;&lt; std::endl;
}
</code></pre>
<p>Ob dir das was hilft ist natürlich fraglich. Was du auf jeden Fall bei deiner Variante noch beachten solltest, ist das der Benutzer falsche Eingaben machen kann (z.B. Buchstaben).</p>
<p>Gruß<br />
Don06</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1550345</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1550345</guid><dc:creator><![CDATA[Don06]]></dc:creator><pubDate>Sun, 20 Jul 2008 17:45:54 GMT</pubDate></item><item><title><![CDATA[Reply to Rechnung mit Array on Sun, 20 Jul 2008 17:21:02 GMT]]></title><description><![CDATA[<p>Ja wie die 1 dareingekommen ist frage ich mich auch gerade.</p>
<p>Jedenfalls habe ich es wie folgt verändert:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;  
using namespace std;

int main()
{
    int a[5];
    int quersumme;

    cout &lt;&lt; &quot;Geben Sie eine vierstellige Zahl ein: &quot;&lt;&lt; endl;
    cin &gt;&gt; a;
    quersumme = a[0] + a[1] + a[2] + a[3];
    cout &lt;&lt; &quot;Quersumme: &quot; &lt;&lt; quersumme &lt;&lt; flush;
}
</code></pre>
<p>Fehler:</p>
<pre><code>1&gt;------ Erstellen gestartet: Projekt: Test, Konfiguration: Debug Win32 ------
1&gt;Kompilieren...
1&gt;first.cpp
1&gt;c:\users\frank\desktop\c++\test\test\first.cpp(10) : error C2679: Binärer Operator '&gt;&gt;': Es konnte kein Operator gefunden werden, der einen rechtsseitigen Operanden vom Typ 'int [5]' akzeptiert (oder keine geeignete Konvertierung möglich)
1&gt;        c:\program files\microsoft visual studio 9.0\vc\include\istream(1144): kann 'std::basic_istream&lt;_Elem,_Traits&gt; &amp;std::operator &gt;&gt;&lt;std::char_traits&lt;char&gt;&gt;(std::basic_istream&lt;_Elem,_Traits&gt; &amp;,signed char *)' sein
1&gt;        with
1&gt;        [
1&gt;            _Elem=char,
1&gt;            _Traits=std::char_traits&lt;char&gt;
1&gt;        ]
1&gt;        c:\program files\microsoft visual studio 9.0\vc\include\istream(1146): oder &quot;std::basic_istream&lt;_Elem,_Traits&gt; &amp;std::operator &gt;&gt;&lt;std::char_traits&lt;char&gt;&gt;(std::basic_istream&lt;_Elem,_Traits&gt; &amp;,signed char &amp;)&quot;
1&gt;        with
1&gt;        [
1&gt;            _Elem=char,
1&gt;            _Traits=std::char_traits&lt;char&gt;
1&gt;        ]
1&gt;        c:\program files\microsoft visual studio 9.0\vc\include\istream(1148): oder &quot;std::basic_istream&lt;_Elem,_Traits&gt; &amp;std::operator &gt;&gt;&lt;std::char_traits&lt;char&gt;&gt;(std::basic_istream&lt;_Elem,_Traits&gt; &amp;,unsigned char *)&quot;
1&gt;        with
1&gt;        [
1&gt;            _Elem=char,
1&gt;            _Traits=std::char_traits&lt;char&gt;
1&gt;        ]
1&gt;        c:\program files\microsoft visual studio 9.0\vc\include\istream(1150): oder &quot;std::basic_istream&lt;_Elem,_Traits&gt; &amp;std::operator &gt;&gt;&lt;std::char_traits&lt;char&gt;&gt;(std::basic_istream&lt;_Elem,_Traits&gt; &amp;,unsigned char &amp;)&quot;
1&gt;        with
1&gt;        [
1&gt;            _Elem=char,
1&gt;            _Traits=std::char_traits&lt;char&gt;
1&gt;        ]
1&gt;        c:\program files\microsoft visual studio 9.0\vc\include\istream(155): oder &quot;std::basic_istream&lt;_Elem,_Traits&gt; &amp;std::basic_istream&lt;_Elem,_Traits&gt;::operator &gt;&gt;(std::basic_istream&lt;_Elem,_Traits&gt; &amp;(__cdecl *)(std::basic_istream&lt;_Elem,_Traits&gt; &amp;))&quot;
1&gt;        with
1&gt;        [
1&gt;            _Elem=char,
1&gt;            _Traits=std::char_traits&lt;char&gt;
1&gt;        ]
1&gt;        c:\program files\microsoft visual studio 9.0\vc\include\istream(161): oder &quot;std::basic_istream&lt;_Elem,_Traits&gt; &amp;std::basic_istream&lt;_Elem,_Traits&gt;::operator &gt;&gt;(std::basic_ios&lt;_Elem,_Traits&gt; &amp;(__cdecl *)(std::basic_ios&lt;_Elem,_Traits&gt; &amp;))&quot;
1&gt;        with
1&gt;        [
1&gt;            _Elem=char,
1&gt;            _Traits=std::char_traits&lt;char&gt;
          //////// Dies Wiederholt sich so ziemlich oft, leicht verändert.
1&gt;        ]
1&gt;        bei Anpassung der Argumentliste '(std::istream, int [5])'
1&gt;Das Buildprotokoll wurde unter &quot;file://c:\Users\Korb\Desktop\C++\Test\Test\Debug\BuildLog.htm&quot; gespeichert.
1&gt;Test - 1 Fehler, 0 Warnung(en)
========== Erstellen: 0 erfolgreich, Fehler bei 1, 0 aktuell, 0 übersprungen ==========
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1550346</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1550346</guid><dc:creator><![CDATA[Frankstyles]]></dc:creator><pubDate>Sun, 20 Jul 2008 17:21:02 GMT</pubDate></item><item><title><![CDATA[Reply to Rechnung mit Array on Sun, 20 Jul 2008 17:26:32 GMT]]></title><description><![CDATA[<p>Hi</p>
<p>Wenn du</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;  
using namespace std;

int main()
{
    int a[5];
    int quersumme;

    cout &lt;&lt; &quot;Geben Sie eine vierstellige Zahl ein: &quot;&lt;&lt; endl;
    cin &gt;&gt; a[0];  // Richtig
    quersumme = a[0] + a[1] + a[2] + a[3];
    cout &lt;&lt; &quot;Quersumme: &quot; &lt;&lt; quersumme &lt;&lt; flush;
}
</code></pre>
<p>schreibst, ist der Fehler weg</p>
<p>lg c4f</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1550351</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1550351</guid><dc:creator><![CDATA[c4f]]></dc:creator><pubDate>Sun, 20 Jul 2008 17:26:32 GMT</pubDate></item><item><title><![CDATA[Reply to Rechnung mit Array on Sun, 20 Jul 2008 17:27:30 GMT]]></title><description><![CDATA[<p>Ähm danke Don06, aber das ist insgesamt noch ein bisschen zu hoch gegriffen für mich! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1550353</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1550353</guid><dc:creator><![CDATA[Frankstyles]]></dc:creator><pubDate>Sun, 20 Jul 2008 17:27:30 GMT</pubDate></item><item><title><![CDATA[Reply to Rechnung mit Array on Sun, 20 Jul 2008 17:34:15 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/13710">@don06</a><br />
Die obige Version des Codes weist bei mir noch fehler auf die etwas mit dem atoi zu tun haben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1550363</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1550363</guid><dc:creator><![CDATA[Frankstyles]]></dc:creator><pubDate>Sun, 20 Jul 2008 17:34:15 GMT</pubDate></item><item><title><![CDATA[Reply to Rechnung mit Array on Sun, 20 Jul 2008 17:45:24 GMT]]></title><description><![CDATA[<p><a href="http://www.cplusplus.com/reference/clibrary/cstdlib/atoi.html" rel="nofollow">http://www.cplusplus.com/reference/clibrary/cstdlib/atoi.html</a><br />
atoi erwartet wohl einen const char* als Parameter. Das ist umständlich...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1550374</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1550374</guid><dc:creator><![CDATA[Don06]]></dc:creator><pubDate>Sun, 20 Jul 2008 17:45:24 GMT</pubDate></item></channel></rss>