<?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[Frage zu Funktion im Taschenrechner Programm]]></title><description><![CDATA[<p>Hallo,</p>
<p>mein erster Taschenrechner den ich gemacht habe der sah so aus:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
using namespace std;
int main()

{
int nummer,zahl1,zahl2,add,zahl3,zahl4,sub,nochmal;

do

{
system(&quot;CLS&quot;);
cout&lt;&lt;&quot;(1) Addieren \n&quot;;
cout&lt;&lt;&quot;(2) Subtrahieren\n&quot;;
cout&lt;&lt;&quot;\n&quot;;
cout&lt;&lt;&quot;Nummer eingeben: &quot;;
cin&gt;&gt;nummer;

if (nummer==1)
{
cout&lt;&lt;&quot;Geben sie die erste Zahl ein: \n&quot;;
cin&gt;&gt;zahl1;
cout&lt;&lt;&quot;Geben sie die zweite Zahl ein: \n&quot;;
cin&gt;&gt;zahl2;
add = zahl1+zahl2;
cout&lt;&lt;&quot;Das Ergebniss lautet&quot;&lt;&lt;add&lt;&lt;&quot;\n&quot;;
cout&lt;&lt;&quot;Wollen sie noch etwas berechne ? 1=Ja, 2=Nein\n&quot;;
cin&gt;&gt;nochmal;
}

if (nummer==2)
{
cout&lt;&lt;&quot;Geben sie die erste Zahl ein: \n&quot;;
cin&gt;&gt;zahl3;
cout&lt;&lt;&quot;Geben sie die zweite Zahl ein: \n&quot;;
cin&gt;&gt;zahl4;
sub = zahl3-zahl4;
cout&lt;&lt;&quot;Das Ergebniss lautet&quot;&lt;&lt;sub&lt;&lt;&quot;\n&quot;;
cout&lt;&lt;&quot;Wollen sie noch etwas berechne ? 1=Ja, 2=Nein\n&quot;;
cin&gt;&gt;nochmal;
}

}
while(nochmal==1);

system(&quot;PAUSE&quot;);
}
</code></pre>
<p>Jetzt möchte ich das aber mal mit den Funktionen ausprobieren, muss man dann da auch die if abfragen in eine extra funktion packen ?</p>
<p>Hier der Source Code:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
using namespace std;

void ausgabe(int menu);

int main ()

{
int menu;
ausgabe(menu);
system(&quot;PAUSE&quot;);
}

void ausgabe(int menu)
{
cout&lt;&lt;&quot;~~Taschenrechner~~\n&quot;;
cout&lt;&lt;&quot;\n&quot;;
cout&lt;&lt;&quot;(1) Addieren\n&quot;;
cout&lt;&lt;&quot;(2) Subtrahieren\n&quot;;
cout&lt;&lt;&quot;\n&quot;;
cout&lt;&lt;&quot;Nummer Eingeben: &quot;;
cin&gt;&gt;menu;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/197935/frage-zu-funktion-im-taschenrechner-programm</link><generator>RSS for Node</generator><lastBuildDate>Thu, 01 Oct 2026 18:53:45 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/197935.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 16 Nov 2007 09:05:32 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Frage zu Funktion im Taschenrechner Programm on Fri, 16 Nov 2007 09:05:32 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>mein erster Taschenrechner den ich gemacht habe der sah so aus:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
using namespace std;
int main()

{
int nummer,zahl1,zahl2,add,zahl3,zahl4,sub,nochmal;

do

{
system(&quot;CLS&quot;);
cout&lt;&lt;&quot;(1) Addieren \n&quot;;
cout&lt;&lt;&quot;(2) Subtrahieren\n&quot;;
cout&lt;&lt;&quot;\n&quot;;
cout&lt;&lt;&quot;Nummer eingeben: &quot;;
cin&gt;&gt;nummer;

if (nummer==1)
{
cout&lt;&lt;&quot;Geben sie die erste Zahl ein: \n&quot;;
cin&gt;&gt;zahl1;
cout&lt;&lt;&quot;Geben sie die zweite Zahl ein: \n&quot;;
cin&gt;&gt;zahl2;
add = zahl1+zahl2;
cout&lt;&lt;&quot;Das Ergebniss lautet&quot;&lt;&lt;add&lt;&lt;&quot;\n&quot;;
cout&lt;&lt;&quot;Wollen sie noch etwas berechne ? 1=Ja, 2=Nein\n&quot;;
cin&gt;&gt;nochmal;
}

if (nummer==2)
{
cout&lt;&lt;&quot;Geben sie die erste Zahl ein: \n&quot;;
cin&gt;&gt;zahl3;
cout&lt;&lt;&quot;Geben sie die zweite Zahl ein: \n&quot;;
cin&gt;&gt;zahl4;
sub = zahl3-zahl4;
cout&lt;&lt;&quot;Das Ergebniss lautet&quot;&lt;&lt;sub&lt;&lt;&quot;\n&quot;;
cout&lt;&lt;&quot;Wollen sie noch etwas berechne ? 1=Ja, 2=Nein\n&quot;;
cin&gt;&gt;nochmal;
}

}
while(nochmal==1);

system(&quot;PAUSE&quot;);
}
</code></pre>
<p>Jetzt möchte ich das aber mal mit den Funktionen ausprobieren, muss man dann da auch die if abfragen in eine extra funktion packen ?</p>
<p>Hier der Source Code:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
using namespace std;

void ausgabe(int menu);

int main ()

{
int menu;
ausgabe(menu);
system(&quot;PAUSE&quot;);
}

void ausgabe(int menu)
{
cout&lt;&lt;&quot;~~Taschenrechner~~\n&quot;;
cout&lt;&lt;&quot;\n&quot;;
cout&lt;&lt;&quot;(1) Addieren\n&quot;;
cout&lt;&lt;&quot;(2) Subtrahieren\n&quot;;
cout&lt;&lt;&quot;\n&quot;;
cout&lt;&lt;&quot;Nummer Eingeben: &quot;;
cin&gt;&gt;menu;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1404133</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1404133</guid><dc:creator><![CDATA[Bassmaster]]></dc:creator><pubDate>Fri, 16 Nov 2007 09:05:32 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu Funktion im Taschenrechner Programm on Fri, 16 Nov 2007 09:10:05 GMT]]></title><description><![CDATA[<p>Das was in deinen if-Abfragen steht solltest du jeweils in Funktionen packen. Also eine Funktion für Zweig 1 und eine weitere für Zweig 2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1404139</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1404139</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Fri, 16 Nov 2007 09:10:05 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu Funktion im Taschenrechner Programm on Fri, 16 Nov 2007 09:11:30 GMT]]></title><description><![CDATA[<p>ok thx</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1404140</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1404140</guid><dc:creator><![CDATA[Bassmaster]]></dc:creator><pubDate>Fri, 16 Nov 2007 09:11:30 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu Funktion im Taschenrechner Programm on Fri, 16 Nov 2007 10:43:45 GMT]]></title><description><![CDATA[<p>Wenn du das Funktional lösen willst, dann so:</p>
<pre><code class="language-cpp">int menu()
    {
         cout &lt;&lt; &quot;Menu ausgeben...&quot; &lt;&lt; endl;
         // ...
         return auswahl;
    }
</code></pre>
<p>Wenn du das Prozedural lösen möchtest:</p>
<pre><code class="language-cpp">void menu(int&amp; menuauswahl)
    {
        cout &lt;&lt; &quot;Menu ausgeben...&quot; &lt;&lt; endl;
        // ...
        menuauswahl = auswahl;
    }
</code></pre>
<p>Wobei ich die funktionale Variante vorzöge, da diese sich angenehmer verwenden lässt, zum Beispiel in switch-case-blöcken:</p>
<pre><code class="language-cpp">switch( menu() ) {
    case 1:
        addieren();
        break;
    case 2:
        subtrahieren();
        break;
    // ...
}
</code></pre>
<p>Und um mit den Worten des Meister Yoda zu schreiben: Vergessen musst, was füher du gelernt (Batch). <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>Grüße... Heiko</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1404171</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1404171</guid><dc:creator><![CDATA[bwbg]]></dc:creator><pubDate>Fri, 16 Nov 2007 10:43:45 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu Funktion im Taschenrechner Programm on Fri, 16 Nov 2007 10:34:46 GMT]]></title><description><![CDATA[<p>Dann solltest du der Funktion menu auch einen Wert zurückgeben lassen, sonst kannst du sie nicht in switch verwenden. Die while-schleife muß ja auch noch bedient werden.</p>
<pre><code class="language-cpp">int menu()
{
    cout &lt;&lt; &quot;Menu ausgeben...&quot; &lt;&lt; endl;
    // ...
    return auswahl;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1404210</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1404210</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Fri, 16 Nov 2007 10:34:46 GMT</pubDate></item></channel></rss>