<?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[Funktion Pow rot unterringelt]]></title><description><![CDATA[<p>Hallo liebe Gemeinde.</p>
<p>Ich wollte die Grundrechenarten +, -, * und / (Geteilt), Potenz und Wurzel als Funktion programmieren.</p>
<p>Dabei wurde folgender Teilcode rot unterringelt:</p>
<pre><code class="language-cpp">float Pot (float m, float n)
{
	cout &lt;&lt; &quot;Funktion Potenz!&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;Zwei Zahlen bitte!&quot; &lt;&lt; endl;
	cin  &gt;&gt; m, n;
	float o = pow (m,n);
	return o;
}
</code></pre>
<p>cout, cin, m,n und return wurden rot unterringelt und ich habe keine Ahnung warum???</p>
<p>Der Gesamtcode ist wie folgt:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;math.h&gt;
using namespace std;

//Funktionen

float Add (float a, float b)
{
	cout &lt;&lt; &quot;Funktion Add!&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;Zwei Zahlen bitte!&quot; &lt;&lt; endl;
	cin  &gt;&gt; a, b;

	float c = a + b;

	return c;
}

float Sub (float d, float e)
{
	cout &lt;&lt; &quot;Funktion Sub!&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;Zwei Zahlen bitte!&quot; &lt;&lt; endl;
	cin  &gt;&gt; d,e;
	float f = d - e;
	return f;
}

float Mul {float g, float h)
{
	cout &lt;&lt; &quot;Funktion Mul!&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;Zwei Zahlen bitte!&quot; &lt;&lt; endl;
	cin  &gt;&gt; g,h;
	float i = g*h;
	return i;
}

float Div (float j, float k)
{
	cout &lt;&lt; &quot;Funktion Div!&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;Zwei Zahlen bitte!&quot; &lt;&lt; endl;
	cin  &gt;&gt; j,k;
	float l = j / k;
	return l;
}

float Pot (float m, float n)
{
	cout &lt;&lt; &quot;Funktion Potenz!&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;Zwei Zahlen bitte!&quot; &lt;&lt; endl;
	cin  &gt;&gt; m, n;
	float o = pow (m,n);
	return o;
}

float Wur (float p)
{
	cout &lt;&lt; &quot;Funktion Wurzel&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;Eine Zahl bitte!&quot; &lt;&lt; endl;
	cin  &gt;&gt; p;
	float q = sqrt (p);
	return q;
}

int main ()
{
	cout &lt;&lt; &quot;Taschenrechner!&quot; &lt;&lt; endl;
	cout &lt;&lt; endl;
	cout &lt;&lt; &quot;1. Addition!&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;2. Subtraktion!&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;3. Multiplikation!&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;4. Division!&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;5. Potenz!&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;6. Wurzel!&quot; &lt;&lt; endl;
	cout &lt;&lt; endl;

	c=Add(a,b);
	f=Sub(d,e);
	i=Mul(g,h);
	l=Div(j,k);
	o=Pot(m,n);
	q=Wur(p);

	return 0;
}
</code></pre>
<p>Hättet ihr einen Tipp bzw. einen Hinweis, warum es falsch ist??</p>
<p>Vielen Danke im Voraus für die Antworten.</p>
<p>Gruß</p>
<p>Max</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/302227/funktion-pow-rot-unterringelt</link><generator>RSS for Node</generator><lastBuildDate>Tue, 11 Aug 2026 10:01:49 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/302227.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 13 Apr 2012 19:01:33 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Funktion Pow rot unterringelt on Fri, 13 Apr 2012 19:01:33 GMT]]></title><description><![CDATA[<p>Hallo liebe Gemeinde.</p>
<p>Ich wollte die Grundrechenarten +, -, * und / (Geteilt), Potenz und Wurzel als Funktion programmieren.</p>
<p>Dabei wurde folgender Teilcode rot unterringelt:</p>
<pre><code class="language-cpp">float Pot (float m, float n)
{
	cout &lt;&lt; &quot;Funktion Potenz!&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;Zwei Zahlen bitte!&quot; &lt;&lt; endl;
	cin  &gt;&gt; m, n;
	float o = pow (m,n);
	return o;
}
</code></pre>
<p>cout, cin, m,n und return wurden rot unterringelt und ich habe keine Ahnung warum???</p>
<p>Der Gesamtcode ist wie folgt:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;math.h&gt;
using namespace std;

//Funktionen

float Add (float a, float b)
{
	cout &lt;&lt; &quot;Funktion Add!&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;Zwei Zahlen bitte!&quot; &lt;&lt; endl;
	cin  &gt;&gt; a, b;

	float c = a + b;

	return c;
}

float Sub (float d, float e)
{
	cout &lt;&lt; &quot;Funktion Sub!&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;Zwei Zahlen bitte!&quot; &lt;&lt; endl;
	cin  &gt;&gt; d,e;
	float f = d - e;
	return f;
}

float Mul {float g, float h)
{
	cout &lt;&lt; &quot;Funktion Mul!&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;Zwei Zahlen bitte!&quot; &lt;&lt; endl;
	cin  &gt;&gt; g,h;
	float i = g*h;
	return i;
}

float Div (float j, float k)
{
	cout &lt;&lt; &quot;Funktion Div!&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;Zwei Zahlen bitte!&quot; &lt;&lt; endl;
	cin  &gt;&gt; j,k;
	float l = j / k;
	return l;
}

float Pot (float m, float n)
{
	cout &lt;&lt; &quot;Funktion Potenz!&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;Zwei Zahlen bitte!&quot; &lt;&lt; endl;
	cin  &gt;&gt; m, n;
	float o = pow (m,n);
	return o;
}

float Wur (float p)
{
	cout &lt;&lt; &quot;Funktion Wurzel&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;Eine Zahl bitte!&quot; &lt;&lt; endl;
	cin  &gt;&gt; p;
	float q = sqrt (p);
	return q;
}

int main ()
{
	cout &lt;&lt; &quot;Taschenrechner!&quot; &lt;&lt; endl;
	cout &lt;&lt; endl;
	cout &lt;&lt; &quot;1. Addition!&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;2. Subtraktion!&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;3. Multiplikation!&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;4. Division!&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;5. Potenz!&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;6. Wurzel!&quot; &lt;&lt; endl;
	cout &lt;&lt; endl;

	c=Add(a,b);
	f=Sub(d,e);
	i=Mul(g,h);
	l=Div(j,k);
	o=Pot(m,n);
	q=Wur(p);

	return 0;
}
</code></pre>
<p>Hättet ihr einen Tipp bzw. einen Hinweis, warum es falsch ist??</p>
<p>Vielen Danke im Voraus für die Antworten.</p>
<p>Gruß</p>
<p>Max</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2201753</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2201753</guid><dc:creator><![CDATA[silent_max]]></dc:creator><pubDate>Fri, 13 Apr 2012 19:01:33 GMT</pubDate></item><item><title><![CDATA[Reply to Funktion Pow rot unterringelt on Fri, 13 Apr 2012 19:28:25 GMT]]></title><description><![CDATA[<p>Deine Klammern passen nicht zusammen. Manchmal benutzt du { und schließt mit ) und ähnliche Scherzchen. Und es ist natürlich immer nur jeweils eines richtig, Konsistenz alleine würde nicht reichen :p .</p>
<p>Außerdem machen Konstrukte wie <code>cin &gt;&gt; a, b;</code> nicht das, was du vermutlich denkst. Du meinst wohl <code>cin &gt;&gt; a &gt;&gt; b;</code> . Und bei den Funktionen meinst du wohl jeweils:</p>
<pre><code class="language-cpp">void Add ()
{
    float a,b;
    cout &lt;&lt; &quot;Funktion Add!&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;Zwei Zahlen bitte!&quot; &lt;&lt; endl;
    cin  &gt;&gt; a, b;

    float c = a + b;

    cout &lt;&lt; c;
}
</code></pre>
<p>Das andere wäre ziemlicher Unsinn, da du die Funktionparameter gar nicht benutzt. Und den Rückgabewert ebenfalls nicht. Dann ruft man sie auf mit <code>Add();</code> . Oder du machst es umgekehrt:</p>
<pre><code class="language-cpp">float Add (float a, float b)
{
 return a + b;
}
</code></pre>
<p>Und liest dann in der main die Zahlen ein und übergibst sie an die Funktion. Dann sieht der Aufruf so ähnlich aus, wie jetzt in der main.</p>
<p>In der main möchtest du vermutlich noch irgendeine Art Kontrollstruktor, vielleicht ein paar if oder ein switch und vielleicht auch eine Schleife, anstatt einfach gar nichts.</p>
<p>Allgemein: Wenn du Fehler hast, einfach mal versuchen zu compilieren. Immer mit höchsten Warnoptionen und Warnungen wie Fehler ansehen. Dann sagt dir der Compiler schon, was nicht stimmt. Diese Fehlermeldungen musst du lesen lernen, um später eigenständig Probleme beheben zu können. Der GCC 4.6 (die Lesbarkeit der Fehlermeldungen dieser Version wurden stark verbessert <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /> ) gibt zu deinem Programm beispielsweise aus:</p>
<pre><code>test.cc: In function ‘float Add(float, float)’:
test.cc:11:17: warning: right operand of comma operator has no effect [-Wunused-value]
test.cc: In function ‘float Sub(float, float)’:
test.cc:22:16: warning: right operand of comma operator has no effect [-Wunused-value]
test.cc: At global scope:
test.cc:27:7: warning: extended initializer lists only available with -std=c++0x or -std=gnu++0x [enabled by default]
test.cc:27:12: error: expected primary-expression before ‘float’
test.cc:27:12: error: expected ‘}’ before ‘float’
test.cc:27:12: error: expected ‘,’ or ‘;’ before ‘float’
test.cc: In function ‘float Div(float, float)’:
test.cc:40:16: warning: right operand of comma operator has no effect [-Wunused-value]
test.cc: In function ‘float Pot(float, float)’:
test.cc:49:17: warning: right operand of comma operator has no effect [-Wunused-value]
test.cc: In function ‘int main()’:
test.cc:75:5: error: ‘c’ was not declared in this scope
test.cc:75:11: error: ‘a’ was not declared in this scope
test.cc:75:13: error: ‘b’ was not declared in this scope
test.cc:76:5: error: ‘f’ was not declared in this scope
test.cc:76:11: error: ‘d’ was not declared in this scope
test.cc:76:13: error: ‘e’ was not declared in this scope
test.cc:77:5: error: ‘i’ was not declared in this scope
test.cc:77:11: error: ‘g’ was not declared in this scope
test.cc:77:13: error: ‘h’ was not declared in this scope
test.cc:77:14: error: ‘Mul’ cannot be used as a function
test.cc:78:5: error: ‘l’ was not declared in this scope
test.cc:78:11: error: ‘j’ was not declared in this scope
test.cc:78:13: error: ‘k’ was not declared in this scope
test.cc:79:5: error: ‘o’ was not declared in this scope
test.cc:79:11: error: ‘m’ was not declared in this scope
test.cc:79:13: error: ‘n’ was not declared in this scope
test.cc:80:5: error: ‘q’ was not declared in this scope
test.cc:80:11: error: ‘p’ was not declared in this scope
</code></pre>
<p>Was all die Probleme abdeckt, die ich angesprochen habe. Daher habe ich sie ja auch so schnell gefunden. Eine falsche klammer sieht man optisch kaum, aber der Compiler (oder ein Editor mit Klammernzählung) sieht das sofort.</p>
<p>Und noch eine Analyse deiner Fehler: Du scheinst noch nicht den rechten Durchblick bei Funktionen, Skopes und den Grundlagen der Streams zu haben. Dringend nachholen! Insbesondere scheinst du zu glauben, dass die Variablennamen in deinen Funktionen auch sonstwo noch gültig wären. Sind sie aber nicht! Und das ist auch gut so!</p>
<p>P.P.S.: Und <code>math.h</code> heißt in C++ <code>cmath</code> (ohne .h!).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2201765</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2201765</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Fri, 13 Apr 2012 19:28:25 GMT</pubDate></item><item><title><![CDATA[Reply to Funktion Pow rot unterringelt on Sat, 14 Apr 2012 10:39:41 GMT]]></title><description><![CDATA[<p>So wie ich dich verstanden habe, darf ich alles neu schreiben??</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2201868</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2201868</guid><dc:creator><![CDATA[silent_max]]></dc:creator><pubDate>Sat, 14 Apr 2012 10:39:41 GMT</pubDate></item><item><title><![CDATA[Reply to Funktion Pow rot unterringelt on Sat, 14 Apr 2012 11:28:00 GMT]]></title><description><![CDATA[<p>silent_max schrieb:</p>
<blockquote>
<p>So wie ich dich verstanden habe, darf ich alles neu schreiben??</p>
</blockquote>
<p>Refactoring ist manchmal <strong>einfach die beste Lösung</strong> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /> (anstatt einfach drumherum zu programmieren bis es <em>irgendwie geht</em> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_down"
      title=":-1:"
      alt="👎"
    /> )</p>
<p>Kleiner Tipp zu Scopes:</p>
<p>Wenn du <code>cout &lt;&lt; irgendwas;</code> schreibst, beachte das:<br />
<code>cout</code> befindet sich im Namensraum <code>std</code> . Das bedeutet, du kannst insgesamt drei Arten wählen, den Namen <code>cout</code> (aus <code>std</code> ) zu verwenden:</p>
<pre><code class="language-cpp">using std::cout; //Hier teilst du dem Compiler mit, dass ein spezifischer Name 
                 //ohne Namensraum + Scope-Operator verwendet werden kann. Also kannst du jetzt 
                 //(nur!) cout ohne std:: schreiben.

using namespace std;//Die IMO schlechteste Lösung: Einfach den kompletten Namensraum ausschütten. Das ist einfach aber nicht schön, bitte gewöhn dir das nicht an.

std::cout &lt;&lt; &quot;Hallo!\n&quot;;//Die eigentlich einfachste Lösung: Einfach std (der Namensraum-Name ^^) und den sog. Scope-Operator :: vor cout schreiben.
</code></pre>
<p>Edit: Natürlich gibt es noch mehr möglichkeiten (die aber alle eig. schlechter sind als die oben genannten (und die auch so keiner verwendet)):</p>
<pre><code class="language-cpp">std::ostream&amp; cout = std::cout;

#define cout std::cout

//Wars das?
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2201874</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2201874</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Sat, 14 Apr 2012 11:28:00 GMT</pubDate></item></channel></rss>