<?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[Pzbildung durch Funktion]]></title><description><![CDATA[<pre><code>#include &lt;iostream&gt;
using namespace std;
double y;
int x;

double pz_test(int param,int y)//Funktion selber
{
    for (int i = 2; i &lt; x; i++)
    {
        if (y%i == 0)
            break;
        else
            y = i+x;
            cout&lt;&lt;y&lt;&lt;&quot; ist jetzt y&quot;;;
    }
    return y;
}

int main(int argc, const char * argv[])
{
        for (x=1;x&gt;=1000;x=x+2)
        {
            y=x;
            pz_test(y); //Funktionsaufruf
            cout&lt;&lt;y&lt;&lt;&quot; ist y jetzt&quot;;
        }
    return 0;
}
</code></pre>
<p>Ich will das jeweilige x als y in die Funktion pz_test bringen. Es funktioniert nicht! Es ist wieder die Argumenteübergabe, an der es hapert ....Er sagt &quot;no matching funktion to pz_test ... aber er sagt nicht, warum pz_test niccht matcht...</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/334824/pzbildung-durch-funktion</link><generator>RSS for Node</generator><lastBuildDate>Sat, 25 Apr 2026 03:56:58 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/334824.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 13 Oct 2015 20:36:42 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Pzbildung durch Funktion on Tue, 13 Oct 2015 20:51:03 GMT]]></title><description><![CDATA[<pre><code>#include &lt;iostream&gt;
using namespace std;
double y;
int x;

double pz_test(int param,int y)//Funktion selber
{
    for (int i = 2; i &lt; x; i++)
    {
        if (y%i == 0)
            break;
        else
            y = i+x;
            cout&lt;&lt;y&lt;&lt;&quot; ist jetzt y&quot;;;
    }
    return y;
}

int main(int argc, const char * argv[])
{
        for (x=1;x&gt;=1000;x=x+2)
        {
            y=x;
            pz_test(y); //Funktionsaufruf
            cout&lt;&lt;y&lt;&lt;&quot; ist y jetzt&quot;;
        }
    return 0;
}
</code></pre>
<p>Ich will das jeweilige x als y in die Funktion pz_test bringen. Es funktioniert nicht! Es ist wieder die Argumenteübergabe, an der es hapert ....Er sagt &quot;no matching funktion to pz_test ... aber er sagt nicht, warum pz_test niccht matcht...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2470900</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2470900</guid><dc:creator><![CDATA[Sonne55]]></dc:creator><pubDate>Tue, 13 Oct 2015 20:51:03 GMT</pubDate></item><item><title><![CDATA[Reply to Pzbildung durch Funktion on Tue, 13 Oct 2015 21:05:04 GMT]]></title><description><![CDATA[<p>Sonne55 schrieb:</p>
<blockquote>
<p>Ich will das jeweilige x als y in die Funktion pz_test bringen. Es funktioniert nicht! Es ist wieder die Argumenteübergabe, an der es hapert ....Er sagt &quot;no matching funktion to pz_test ... aber er sagt nicht, warum pz_test niccht matcht...</p>
</blockquote>
<p>Die von dir definierte Funktion pz_test hat zwei Parameter, der von dir aufgerufene Funktion übergibst du einen.</p>
<p>Ansonsten kann ich keine weiteren Kommentare zu deinem Code abgeben, weil mir ein absolutes Rätsel ist, was du dir dabei gedacht hast. Was vermutlich heißt, dass dein Code selbst nach der Korrektur obigen Fehlers nicht so funktionieren wird, wie du es dir vorgestellt hast. Kann es sein, dass du einfach so lange quasi-zufällig Variablendefinitionen und anderen Code hinzu gefügt hast, bis am Ende nur noch eine Fehlermeldung übrig war?</p>
<p>Allgemein sind globale Variablen jedoch höchst gefährlich in den Händen von Anfängern und sollten von diesen um jeden Preis vermieden werden, da sie zu absolut unnachvollziehbarem Code (und damit auch unnachvollziehbaren Fehlern) führen. Dein Code scheint ein Vorzeigebeispiel dafür zu sein. Wenn ich keine Ahnung habe, was dein Code macht bzw. machen soll, ist davon auszugehen, dass du das auch nicht wirklich weißt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2470903</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2470903</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Tue, 13 Oct 2015 21:05:04 GMT</pubDate></item><item><title><![CDATA[Reply to Pzbildung durch Funktion on Tue, 13 Oct 2015 21:21:05 GMT]]></title><description><![CDATA[<p>Okay, ich machs einfacher. Will einfach nur erst einmal einen Funktionsaufruf zum Laufen bringen... jetzt läuft er, okay</p>
<pre><code>#include &lt;iostream&gt;
using namespace std;
int y;

int pz_test(int param)//Funktion selber
{
    y=param+5;
    return y;
}

int main(int argc, const char * argv[])
{
            cout&lt;&lt;&quot;in main&quot;&lt;&lt;&quot;\n&quot;;
        for (int x=1;x&lt;=10;x=x+2)
        {

            cout&lt;&lt;&quot;in for&quot;&lt;&lt;&quot;\n&quot;;
            pz_test(x); //Funktionsaufruf
            cout&lt;&lt;y&lt;&lt;&quot; ist y jetzt in main \n&quot;;
        }
    return 0;
}
</code></pre>
<p>Morgen packen wir den PZ Test rein ...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2470905</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2470905</guid><dc:creator><![CDATA[Sonne55]]></dc:creator><pubDate>Tue, 13 Oct 2015 21:21:05 GMT</pubDate></item><item><title><![CDATA[Reply to Pzbildung durch Funktion on Tue, 13 Oct 2015 21:13:58 GMT]]></title><description><![CDATA[<p>Der zweite Teil einer for-Schleife ist keine <strong>Abbruch</strong>bedingung, sondern eine <strong>Lauf</strong>bedingung.</p>
<p>All diese Dinge sind absolute Grundlagen, es ist kaum nachvollziehbar, wie du for-Schleifen und Funktionen kennen kannst, ohne diese Dinge zu wissen. Wie lernst du C++? Deine Methode bzw. dein Lehrer/Lehrmaterial scheint absolut nichts zu taugen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2470907</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2470907</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Tue, 13 Oct 2015 21:13:58 GMT</pubDate></item><item><title><![CDATA[Reply to Pzbildung durch Funktion on Tue, 13 Oct 2015 21:15:10 GMT]]></title><description><![CDATA[<p>Wie schon gesagt besser mal die globalen Variablen weglassen:</p>
<pre><code>#include &lt;iostream&gt;
using namespace std;

int pz_test(int param)//Funktion selber
{
  int y = param + 5;
  return y;
}

int main(int argc, const char * argv[])
{
  cout &lt;&lt; &quot;in main&quot; &lt;&lt; &quot;&quot;;
  for(int x = 1; x &lt;= 1000; x = x + 2)
  {
    cout &lt;&lt; &quot;in for&quot; &lt;&lt; &quot;&quot;;
    int y = pz_test(x); //Funktionsaufruf
    cout &lt;&lt; y &lt;&lt; &quot; ist y jetzt&quot;;
  }
  return 0;
}
</code></pre>
<p>Dein Code hat nichts ausgegeben weil bei deiner for Schleife die Bedingung falsch war. Du wolltest wohl solange etwas ausgaben wie x <strong>kleiner</strong> als 1000 ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2470908</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2470908</guid><dc:creator><![CDATA[sebi707]]></dc:creator><pubDate>Tue, 13 Oct 2015 21:15:10 GMT</pubDate></item><item><title><![CDATA[Reply to Pzbildung durch Funktion on Tue, 13 Oct 2015 21:33:09 GMT]]></title><description><![CDATA[<p>Noch als Nachtrag: Die Variable <code>y</code> in der main Funktion hat rein gar nichts mit der Variable <code>y</code> in der pz_test Funktion zu tun. Ich kann die Variable in der main auch <code>z</code> oder was auch immer nennen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2470914</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2470914</guid><dc:creator><![CDATA[sebi707]]></dc:creator><pubDate>Tue, 13 Oct 2015 21:33:09 GMT</pubDate></item><item><title><![CDATA[Reply to Pzbildung durch Funktion on Wed, 14 Oct 2015 06:03:17 GMT]]></title><description><![CDATA[<p>sebi707 schrieb:</p>
<blockquote>
<p>Noch als Nachtrag: Die Variable <code>y</code> in der main Funktion hat rein gar nichts mit der Variable <code>y</code> in der pz_test Funktion zu tun. Ich kann die Variable in der main auch <code>z</code> oder was auch immer nennen.</p>
</blockquote>
<pre><code>#include &lt;iostream&gt;
using namespace std;
int y;

int pz_test(int param)//Funktion selber
{
    y=param+5;
    return y;
}

int main(int argc, const char * argv[])
{
        for (int x=1;x&lt;=10;x=x+2)
        {
            cout&lt;&lt;x&lt;&lt;&quot; ist x&quot;&lt;&lt;&quot;\n&quot;;
            pz_test(x); //Funktionsaufruf
            cout&lt;&lt;y&lt;&lt;&quot; ist y jetzt \n&quot;;
        }
    return 0;
}
</code></pre>
<p>Ich habs nochmal vereinfacht! Also die globale Variable y sei schlechter Stil, weil sie suggeriert, daß das y von return in Funktion, dieselbe Variable sei, wie das y im Main-cout. Dabei passiert in Wirklichkeit nur ein Kopieren innerhalb der verschiedenen Variablen.</p>
<p>Warum funktioniert es dann aber nicht, wenn ich das Main-cout verzette und oben ein int z hinschreibe?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2470930</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2470930</guid><dc:creator><![CDATA[Sonne55]]></dc:creator><pubDate>Wed, 14 Oct 2015 06:03:17 GMT</pubDate></item><item><title><![CDATA[Reply to Pzbildung durch Funktion on Wed, 14 Oct 2015 06:12:10 GMT]]></title><description><![CDATA[<p>Was funktioniert denn nicht? Compilerfehler? Laufzeitfehler? Dir gefällt das Ergebnis nicht? Solltest du <em>immer</em> mit aufschreiben, wenn irgendwas 'nicht funktioniert'.<br />
Ich versteh immer noch nicht warum du eine globale Variable y hast und warum du nicht einfach den Rückgabewert der Funktion benutzt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2470932</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2470932</guid><dc:creator><![CDATA[Techel]]></dc:creator><pubDate>Wed, 14 Oct 2015 06:12:10 GMT</pubDate></item><item><title><![CDATA[Reply to Pzbildung durch Funktion on Wed, 14 Oct 2015 06:26:22 GMT]]></title><description><![CDATA[<p>roflo schrieb:</p>
<blockquote>
<p>Ich versteh immer noch nicht warum du eine globale Variable y hast und</p>
</blockquote>
<p>weil es dann nicht funktioniert, wennn ich die Initialisierung in die Funktion reinnnehme, dann sagte er nämlich zum Main-y &quot;unknow ....&quot;</p>
<p>roflo schrieb:</p>
<blockquote>
<p>warum du nicht einfach den Rückgabewert der Funktion benutzt.</p>
</blockquote>
<p>Mach mal Beispiel was, Du meinst. Bei mir ist doch der Rückgabewert y, weil er hinter return in der funkt steht. Also nutze ich ihn...</p>
<p>kukk mal, was passiert ... 2 x unknown Identifyer</p>
<pre><code>#include &lt;iostream&gt;
using namespace std;

int pz_test(int param, int y)//Funktion selber
{
    y=param+5;
    return y;
}

int main(int argc, const char * argv[])
{
        for (int x=1;x&lt;=10;x=x+2)
        {
            cout&lt;&lt;&quot;x ist &quot;&lt;&lt;x&lt;&lt;&quot; so &quot;&lt;&lt;&quot;\n&quot;;
            pz_test(x, y); //Funktionsaufruf
            cout&lt;&lt;y&lt;&lt;&quot; ist y jetzt \n&quot;;
        }
    return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2470933</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2470933</guid><dc:creator><![CDATA[Sonne55]]></dc:creator><pubDate>Wed, 14 Oct 2015 06:26:22 GMT</pubDate></item><item><title><![CDATA[Reply to Pzbildung durch Funktion on Wed, 14 Oct 2015 06:29:16 GMT]]></title><description><![CDATA[<p>Sonne55 schrieb:</p>
<blockquote>
<p>Also nutze ich ihn...</p>
</blockquote>
<p>Du nutzt ihn dort, wo die Funktion aufgerufen wird, nicht.</p>
<p>Da müsste</p>
<pre><code>int foo = pz_test(x);
</code></pre>
<p>oder so stehen. Dann steht der Rückgabewert in foo, und du kannst damit weiter arbeiten.</p>
<p>Da du das nicht tust, funktioniert es nur mit der globalen Variablen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2470934</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2470934</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Wed, 14 Oct 2015 06:29:16 GMT</pubDate></item><item><title><![CDATA[Reply to Pzbildung durch Funktion on Wed, 14 Oct 2015 07:01:54 GMT]]></title><description><![CDATA[<p>Ist es so okay?</p>
<pre><code>#include &lt;iostream&gt;
using namespace std;

int pz_test(int param1)//Funktion selber
{
 int Ergebnis=param1+5;
    return Ergebnis;
}

int main(int argc, const char * argv[])
{
        for (int x=1;x&lt;=10;x=x+2)
        {
            cout&lt;&lt;&quot;x ist &quot;&lt;&lt;x&lt;&lt;&quot; so &quot;&lt;&lt;&quot;\n&quot;;
            cout&lt;&lt;&quot;Funktionsergebnis ist&quot;&lt;&lt;pz_test(x)&lt;&lt;&quot; \n&quot;; //Funktionsaufruf
        }
    return 0;
}
</code></pre>
<p>Was ich nicht versteh, wie das Ergebnis von Funktion in das x vom Funktionsaufruf kommt, obwohl keine Zuweisung stattgefunden hat. Ich dachte, das x ist der Wert, den Main in die Funktion liefert, dabei scheint es den Wert zu präsentieren, der von der Funktion nach Main zurückkommt....</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2470935</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2470935</guid><dc:creator><![CDATA[Sonne55]]></dc:creator><pubDate>Wed, 14 Oct 2015 07:01:54 GMT</pubDate></item><item><title><![CDATA[Reply to Pzbildung durch Funktion on Wed, 14 Oct 2015 07:26:19 GMT]]></title><description><![CDATA[<p>Wie kommst du darauf? x wir von der Funktion nicht geändert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2470938</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2470938</guid><dc:creator><![CDATA[Techel]]></dc:creator><pubDate>Wed, 14 Oct 2015 07:26:19 GMT</pubDate></item><item><title><![CDATA[Reply to Pzbildung durch Funktion on Wed, 14 Oct 2015 08:57:31 GMT]]></title><description><![CDATA[<p>Der Code ist in Ordnung, deine Erklärung aber nicht so ganz. Vielleicht fügst du dir nochmal eine Ausgabe von <code>x</code> nach dem Funktionsaufruf hinzu:</p>
<pre><code>for (int x=1;x&lt;=10;x=x+2)
{
    cout&lt;&lt;&quot;x ist &quot;&lt;&lt;x&lt;&lt;&quot; so &quot;&lt;&lt;&quot;\n&quot;;
    cout&lt;&lt;&quot;Funktionsergebnis ist&quot;&lt;&lt;pz_test(x)&lt;&lt;&quot; \n&quot;; //Funktionsaufruf
    cout&lt;&lt;&quot;x ist &quot;&lt;&lt;x&lt;&lt;&quot; so &quot;&lt;&lt;&quot;\n&quot;
}
</code></pre>
<p>Du wirst feststellen, dass sich der Wert von <code>x</code> nach dem Funktionsaufruf gar nicht geändert hat. Ist ja auch kein Wunder denn du hast wie du selbst schreibst keine Zuweisung. In der Zeile mit dem Funktionsaufruf wird die Funktion mit x aufgerufen und gibt dann irgendein Ergebnis zurück, welches du direkt ausgibst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2470947</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2470947</guid><dc:creator><![CDATA[sebi707]]></dc:creator><pubDate>Wed, 14 Oct 2015 08:57:31 GMT</pubDate></item></channel></rss>