<?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[switch Anweisung?]]></title><description><![CDATA[<p>Hi Leute!</p>
<p>Ich soll sowas wie einen Taschenrechner programmieren.</p>
<p>Hier mein Code:</p>
<pre><code class="language-cpp">#include&lt;iostream&gt;
using namespace std;

int main()
{
char op;
int zahl1, zahl2, erg;

cout &lt;&lt; &quot;Zahl 1 eingeben: &quot;;
cin &gt;&gt; zahl1;

cout &lt;&lt; endl &lt;&lt; &quot;Operator eingeben (moeglicher Operator: +, -, *, /, %): &quot;;
cin &gt;&gt; op;

cout &lt;&lt; endl &lt;&lt; &quot;Zahl 2 eingeben: &quot;;
cin &gt;&gt; zahl2;

switch (op)
{
case 43:
     cout &lt;&lt; &quot;Sie befinden sich in Addition&quot; &lt;&lt; endl;
     erg = zahl1 + zahl2;
     cout &lt;&lt; &quot;Ergebnis der Addition: &quot; &lt;&lt; erg;
     break;

case 45:
     cout &lt;&lt; &quot;Sie befinden sich in Subtraktion&quot; &lt;&lt; endl;
     erg = zahl1 - zahl2;
     cout &lt;&lt; &quot;Ergebnis der Subtraktion: &quot; &lt;&lt; erg;
     break;

case 42:
     cout &lt;&lt; &quot;Sie befinden sich in Multiplikation&quot; &lt;&lt; endl;
     erg = zahl1 * zahl2;
     cout &lt;&lt; &quot;Ergebnis der Multiplikation: &quot; &lt;&lt; erg;
     break;

case 47:
     cout &lt;&lt; &quot;Sie befinden sich in Division&quot; &lt;&lt; endl;
     erg = zahl1 / zahl2;
     cout &lt;&lt; &quot;Ergebnis der Division: &quot; &lt;&lt; erg;
     break;

case 37:
     cout &lt;&lt; &quot;Sie befinden sich in Modulo&quot; &lt;&lt; endl;
     erg = zahl1 % zahl2;
     cout &lt;&lt; &quot;Ergebnis von Modulo: &quot; &lt;&lt; erg;
     break;

default: 
        cout &lt;&lt; &quot;Ende&quot;;
        break;
}

system(&quot;pause&quot;);
return 0;   
}
</code></pre>
<p>Nun möchte ich, dass ich nach der ersten Berechnung von einem der cases wiederholt einen Operator eingeben bzw. mit einem q das Programm beenden kann. Falls man eine Operator eingegeben hat soll man noch eine weitere Zahl eingeben können. Nach dieser Eingabe der Zahl soll nun wiederholt das richtige Ergebnis angezeigt werden. Danach sollen wiederholt eingaben möglich sein und zwar bei der Eingabe des Operators...</p>
<p>Könnt ihr mir helfen?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/277015/switch-anweisung</link><generator>RSS for Node</generator><lastBuildDate>Wed, 26 Aug 2026 01:52:01 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/277015.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 11 Nov 2010 14:59:33 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to switch Anweisung? on Thu, 11 Nov 2010 14:59:33 GMT]]></title><description><![CDATA[<p>Hi Leute!</p>
<p>Ich soll sowas wie einen Taschenrechner programmieren.</p>
<p>Hier mein Code:</p>
<pre><code class="language-cpp">#include&lt;iostream&gt;
using namespace std;

int main()
{
char op;
int zahl1, zahl2, erg;

cout &lt;&lt; &quot;Zahl 1 eingeben: &quot;;
cin &gt;&gt; zahl1;

cout &lt;&lt; endl &lt;&lt; &quot;Operator eingeben (moeglicher Operator: +, -, *, /, %): &quot;;
cin &gt;&gt; op;

cout &lt;&lt; endl &lt;&lt; &quot;Zahl 2 eingeben: &quot;;
cin &gt;&gt; zahl2;

switch (op)
{
case 43:
     cout &lt;&lt; &quot;Sie befinden sich in Addition&quot; &lt;&lt; endl;
     erg = zahl1 + zahl2;
     cout &lt;&lt; &quot;Ergebnis der Addition: &quot; &lt;&lt; erg;
     break;

case 45:
     cout &lt;&lt; &quot;Sie befinden sich in Subtraktion&quot; &lt;&lt; endl;
     erg = zahl1 - zahl2;
     cout &lt;&lt; &quot;Ergebnis der Subtraktion: &quot; &lt;&lt; erg;
     break;

case 42:
     cout &lt;&lt; &quot;Sie befinden sich in Multiplikation&quot; &lt;&lt; endl;
     erg = zahl1 * zahl2;
     cout &lt;&lt; &quot;Ergebnis der Multiplikation: &quot; &lt;&lt; erg;
     break;

case 47:
     cout &lt;&lt; &quot;Sie befinden sich in Division&quot; &lt;&lt; endl;
     erg = zahl1 / zahl2;
     cout &lt;&lt; &quot;Ergebnis der Division: &quot; &lt;&lt; erg;
     break;

case 37:
     cout &lt;&lt; &quot;Sie befinden sich in Modulo&quot; &lt;&lt; endl;
     erg = zahl1 % zahl2;
     cout &lt;&lt; &quot;Ergebnis von Modulo: &quot; &lt;&lt; erg;
     break;

default: 
        cout &lt;&lt; &quot;Ende&quot;;
        break;
}

system(&quot;pause&quot;);
return 0;   
}
</code></pre>
<p>Nun möchte ich, dass ich nach der ersten Berechnung von einem der cases wiederholt einen Operator eingeben bzw. mit einem q das Programm beenden kann. Falls man eine Operator eingegeben hat soll man noch eine weitere Zahl eingeben können. Nach dieser Eingabe der Zahl soll nun wiederholt das richtige Ergebnis angezeigt werden. Danach sollen wiederholt eingaben möglich sein und zwar bei der Eingabe des Operators...</p>
<p>Könnt ihr mir helfen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1978992</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1978992</guid><dc:creator><![CDATA[bandchef]]></dc:creator><pubDate>Thu, 11 Nov 2010 14:59:33 GMT</pubDate></item><item><title><![CDATA[Reply to switch Anweisung? on Thu, 11 Nov 2010 15:39:38 GMT]]></title><description><![CDATA[<p>Im C Forum habe ich mal sowas ähnliches gepostet:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;map&gt;
#include &lt;boost/array.hpp&gt;
#include &lt;boost/tr1/functional.hpp&gt;

template&lt;typename T&gt;
class calculator {
  int valnr;
  bool read_op(char&amp; c) {
    std::cout &lt;&lt; &quot;Operator eingeben (moeglicher Operator: +, -, *, /): &quot;;
    std::cin &gt;&gt; c; return ops.find(c)!=ops.end(); }
  T read_value() {
    std::cout &lt;&lt; &quot;Zahl &quot;&lt;&lt; ++valnr &lt;&lt; &quot; eingeben: &quot;;
    T val; while (!(std::cin &gt;&gt; val)); return val; }
  std::map&lt;T, std::tr1::function&lt;T(T,T)&gt; &gt; ops;
public:
  calculator() : valnr(0) {
    ops['+'] = std::plus      &lt;T&gt;();
    ops['-'] = std::minus     &lt;T&gt;();
    ops['*'] = std::multiplies&lt;T&gt;();
    ops['/'] = std::divides   &lt;T&gt;();
  }
  T calc() {
    T a=read_value(); char op; while(!read_op(op)); T b=read_value();
    return ops[op](a, b);
  }
  bool recalc(T&amp; value) {
    char op; if (!read_op(op)) return false;
    T a=read_value(); value=ops[op](value, a); return true;
 }
};
template&lt;typename T&gt; void calc()
{
  calculator&lt;T&gt; c; T value(c.calc());
  do std::cout &lt;&lt; &quot;Ergebnis: &quot; &lt;&lt; value &lt;&lt; std::endl;
  while (c.recalc(value));
}

template&lt;typename InputIterator&gt;
InputIterator prompt_pair(InputIterator first, InputIterator last, int firstnum=0)
{
  InputIterator it = first; int nr;
  for (int i=firstnum; it!=last; it++,i++)
    std::cout &lt;&lt; '[' &lt;&lt; i &lt;&lt; &quot;] für &quot; &lt;&lt; it-&gt;first &lt;&lt; std::endl;
  while (!(std::cin &gt;&gt; nr &amp;&amp; nr-firstnum&gt;=0 &amp;&amp; nr-firstnum&lt;last-first));
  std::cout &lt;&lt; &quot;Auswahl: &quot; &lt;&lt; nr &lt;&lt; std::endl;
  std::advance(first, nr-firstnum);
  return first;
}

int main()
{
  boost::array&lt;std::pair&lt;const char*, std::tr1::function&lt;void()&gt; &gt;, 4&gt; choices =
    { { { &quot;Ganzzahlen&quot;,                   &amp;calc&lt;int&gt;        },
        { &quot;Gleitkommazahlen&quot;,             &amp;calc&lt;float&gt;      },
        { &quot;Genaue Gleitkommazahlen&quot;,      &amp;calc&lt;double&gt;     },
        { &quot;Sehr genaue Gleitkommazahlen&quot;, &amp;calc&lt;long double&gt;} } };
  std::cout &lt;&lt; &quot;Welcher Datentyp?&quot; &lt;&lt; std::endl;
  prompt_pair(choices.begin(), choices.end())-&gt;second();
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1979010</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1979010</guid><dc:creator><![CDATA[real c++ programmer]]></dc:creator><pubDate>Thu, 11 Nov 2010 15:39:38 GMT</pubDate></item><item><title><![CDATA[Reply to switch Anweisung? on Thu, 11 Nov 2010 15:49:28 GMT]]></title><description><![CDATA[<p>huhu,</p>
<p>für Wiederholung benötigst du Schleifen. Es gibt die do-while- / while- / und for-Schleife. Diese solltest du dir einaml anschauen.</p>
<p>mfg dweb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1979012</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1979012</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Thu, 11 Nov 2010 15:49:28 GMT</pubDate></item><item><title><![CDATA[Reply to switch Anweisung? on Thu, 11 Nov 2010 16:44:12 GMT]]></title><description><![CDATA[<p>Ich soll laut Aufgabenstellung aber keine Schleifen benutzen. Kann mir aber auch nicht vorstellen wie das dann gehen soll</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1979057</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1979057</guid><dc:creator><![CDATA[bandchef]]></dc:creator><pubDate>Thu, 11 Nov 2010 16:44:12 GMT</pubDate></item><item><title><![CDATA[Reply to switch Anweisung? on Thu, 11 Nov 2010 16:48:46 GMT]]></title><description><![CDATA[<p>real c++ programmer schrieb:</p>
<blockquote>
<p>Im C Forum habe ich mal sowas ähnliches gepostet:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;map&gt;
#include &lt;boost/array.hpp&gt;
#include &lt;boost/tr1/functional.hpp&gt;

template&lt;typename T&gt;
class calculator {
  int valnr;
  bool read_op(char&amp; c) {
    std::cout &lt;&lt; &quot;Operator eingeben (moeglicher Operator: +, -, *, /): &quot;;
    std::cin &gt;&gt; c; return ops.find(c)!=ops.end(); }
  T read_value() {
    std::cout &lt;&lt; &quot;Zahl &quot;&lt;&lt; ++valnr &lt;&lt; &quot; eingeben: &quot;;
    T val; while (!(std::cin &gt;&gt; val)); return val; }
  std::map&lt;T, std::tr1::function&lt;T(T,T)&gt; &gt; ops;
public:
  calculator() : valnr(0) {
    ops['+'] = std::plus      &lt;T&gt;();
    ops['-'] = std::minus     &lt;T&gt;();
    ops['*'] = std::multiplies&lt;T&gt;();
    ops['/'] = std::divides   &lt;T&gt;();
  }
  T calc() {
    T a=read_value(); char op; while(!read_op(op)); T b=read_value();
    return ops[op](a, b);
  }
  bool recalc(T&amp; value) {
    char op; if (!read_op(op)) return false;
    T a=read_value(); value=ops[op](value, a); return true;
 }
};
template&lt;typename T&gt; void calc()
{
  calculator&lt;T&gt; c; T value(c.calc());
  do std::cout &lt;&lt; &quot;Ergebnis: &quot; &lt;&lt; value &lt;&lt; std::endl;
  while (c.recalc(value));
}

template&lt;typename InputIterator&gt;
InputIterator prompt_pair(InputIterator first, InputIterator last, int firstnum=0)
{
  InputIterator it = first; int nr;
  for (int i=firstnum; it!=last; it++,i++)
    std::cout &lt;&lt; '[' &lt;&lt; i &lt;&lt; &quot;] für &quot; &lt;&lt; it-&gt;first &lt;&lt; std::endl;
  while (!(std::cin &gt;&gt; nr &amp;&amp; nr-firstnum&gt;=0 &amp;&amp; nr-firstnum&lt;last-first));
  std::cout &lt;&lt; &quot;Auswahl: &quot; &lt;&lt; nr &lt;&lt; std::endl;
  std::advance(first, nr-firstnum);
  return first;
}

int main()
{
  boost::array&lt;std::pair&lt;const char*, std::tr1::function&lt;void()&gt; &gt;, 4&gt; choices =
    { { { &quot;Ganzzahlen&quot;,                   &amp;calc&lt;int&gt;        },
        { &quot;Gleitkommazahlen&quot;,             &amp;calc&lt;float&gt;      },
        { &quot;Genaue Gleitkommazahlen&quot;,      &amp;calc&lt;double&gt;     },
        { &quot;Sehr genaue Gleitkommazahlen&quot;, &amp;calc&lt;long double&gt;} } };
  std::cout &lt;&lt; &quot;Welcher Datentyp?&quot; &lt;&lt; std::endl;
  prompt_pair(choices.begin(), choices.end())-&gt;second();
}
</code></pre>
</blockquote>
<p>Hat nichts mit der Frage zu tun, sondern ist nur eine Übung zu Funktionszeigern und Templates.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1979058</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1979058</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Thu, 11 Nov 2010 16:48:46 GMT</pubDate></item><item><title><![CDATA[Reply to switch Anweisung? on Thu, 11 Nov 2010 16:49:19 GMT]]></title><description><![CDATA[<p>Wie soll das denn ohne Schleifen funktionieren ?</p>
<p>Vllt. wenn du deine Anweisungen per Hand 30 mal hinklatschst ...<br />
Von wem/wo kommt die Aufgabenstellung?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1979059</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1979059</guid><dc:creator><![CDATA[Felixxx]]></dc:creator><pubDate>Thu, 11 Nov 2010 16:49:19 GMT</pubDate></item><item><title><![CDATA[Reply to switch Anweisung? on Thu, 11 Nov 2010 16:51:30 GMT]]></title><description><![CDATA[<p>bandchef schrieb:</p>
<blockquote>
<p>Ich soll laut Aufgabenstellung aber keine Schleifen benutzen. Kann mir aber auch nicht vorstellen wie das dann gehen soll</p>
</blockquote>
<p>Dann mal bitte den genauen Wortlaut der Aufgabe.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1979061</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1979061</guid><dc:creator><![CDATA[Jockelx]]></dc:creator><pubDate>Thu, 11 Nov 2010 16:51:30 GMT</pubDate></item><item><title><![CDATA[Reply to switch Anweisung? on Thu, 11 Nov 2010 16:52:28 GMT]]></title><description><![CDATA[<p>Theoretisch ginge das ohne Schleifen mittels Rekursion, aber ich bin mir sehr sicher, dass du deine Aufgabenstellung nicht verstanden hast.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1979063</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1979063</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Thu, 11 Nov 2010 16:52:28 GMT</pubDate></item><item><title><![CDATA[Reply to switch Anweisung? on Thu, 11 Nov 2010 16:53:15 GMT]]></title><description><![CDATA[<p>bandchef schrieb:</p>
<blockquote>
<p>Ich soll laut Aufgabenstellung aber keine Schleifen benutzen. Kann mir aber auch nicht vorstellen wie das dann gehen soll</p>
</blockquote>
<p>Dann baust du dir halt Schleifen mit einem goto nach.</p>
<p>Oder du verwendest, falls das bei dir eine Übung zu Funktionszeigern und Templates ist, die Alternative.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1979064</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1979064</guid><dc:creator><![CDATA[goto_origin]]></dc:creator><pubDate>Thu, 11 Nov 2010 16:53:15 GMT</pubDate></item><item><title><![CDATA[Reply to switch Anweisung? on Thu, 11 Nov 2010 16:54:36 GMT]]></title><description><![CDATA[<p>Dann würde ich die Aufgabe lieber unerledigt lassen als sie mit goto zu lösen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1979065</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1979065</guid><dc:creator><![CDATA[Felixxx]]></dc:creator><pubDate>Thu, 11 Nov 2010 16:54:36 GMT</pubDate></item><item><title><![CDATA[Reply to switch Anweisung? on Thu, 11 Nov 2010 16:56:43 GMT]]></title><description><![CDATA[<p>Ich glaub ich geb euch mal die ganze Aufgabenstellung:</p>
<p>Implementieren Sie einen einfachen Taschenrechner. Der Taschenrechner erwartet Eingaben<br />
von ganzen Zahlen und Operatoren (+, -, *, /, <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f635.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--dizzy_face"
      title="%)"
      alt="😵"
    /> und berechnet jeweils das Ergebnis der<br />
eingegebenen Rechnung, ohne jedoch Punkt-vor-Strich-Rechnung zu berücksichtigen. Die<br />
Operatoren haben die aus C bekannte Semantik. Folgendes Eingabeschema soll der Benutzer<br />
ausführen können:<br />
1. Die erste Eingabe muss eine Zahl sein.<br />
2. Die zweite Eingabe muss ein Operator (siehe oben) oder das Zeichen ‘q‘ für „quit“ sein.<br />
3. Die dritte Eingabe muss eine Zahl sein.<br />
4. Nach der dritten Eingabe wird das Ergebnis der bisherigen Eingabe angezeigt und weitere Eingaben dürfen folgen.<br />
5. Die nächste Eingabe muss ein Operator oder ‘q‘ sein.<br />
6. Die nächste Eingabe muss eine Zahl sein.<br />
7. Nach der Eingabe in Schritt 6. wird das Ergebnis der bisherigen Eingabe angezeigt<br />
und weitere Eingaben dürfen folgen. Hierzu wiederhole ab Schritt 5.<br />
Die Eingabe von ‘q‘ anstelle eines Operators beendet das Programm. Vorher geben Sie jedoch bitte noch das Endergebnis der Rechnung aus.</p>
<p>Verwenden Sie zur Auswertung des Operators bitte eine switch-Anweisung.</p>
<p>EDIT: Goto-Sprünge ist schlechter Stil welchen unser Prof ein paar mal erwähnt und somit mit Sicherheit goto auf Flach fällt</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1979070</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1979070</guid><dc:creator><![CDATA[bandchef]]></dc:creator><pubDate>Thu, 11 Nov 2010 16:56:43 GMT</pubDate></item><item><title><![CDATA[Reply to switch Anweisung? on Thu, 11 Nov 2010 16:59:58 GMT]]></title><description><![CDATA[<p>Und wo steht da jetzt, dass du keine Schleife verwenden darfst?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1979071</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1979071</guid><dc:creator><![CDATA[Jockelx]]></dc:creator><pubDate>Thu, 11 Nov 2010 16:59:58 GMT</pubDate></item><item><title><![CDATA[Reply to switch Anweisung? on Thu, 11 Nov 2010 17:02:27 GMT]]></title><description><![CDATA[<p>Hmm wo steht denn, dass du keine Schleifen verwenden darfst?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1979072</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1979072</guid><dc:creator><![CDATA[Felixxx]]></dc:creator><pubDate>Thu, 11 Nov 2010 17:02:27 GMT</pubDate></item><item><title><![CDATA[Reply to switch Anweisung? on Thu, 11 Nov 2010 17:03:03 GMT]]></title><description><![CDATA[<p>&quot;Verwenden Sie zur Auswertung des Operators bitte eine switch-Anweisung.&quot;</p>
<p>Ich hab das so verstanden, dass sich der Satz auf die ganze Aufgabe bezieht...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1979074</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1979074</guid><dc:creator><![CDATA[bandchef]]></dc:creator><pubDate>Thu, 11 Nov 2010 17:03:03 GMT</pubDate></item><item><title><![CDATA[Reply to switch Anweisung? on Thu, 11 Nov 2010 17:05:02 GMT]]></title><description><![CDATA[<p>Ne, wieso denn.</p>
<p>Das Auswerten der Operatoren mit switch Anweisung ist ja logisch.<br />
Das hat aber mit dem Rest des Programmes wenig zu tun.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1979075</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1979075</guid><dc:creator><![CDATA[Felixxx]]></dc:creator><pubDate>Thu, 11 Nov 2010 17:05:02 GMT</pubDate></item><item><title><![CDATA[Reply to switch Anweisung? on Thu, 11 Nov 2010 17:16:04 GMT]]></title><description><![CDATA[<p>Hm, ok, das nimmt natürlich dann der Aufgabe seinen Schrecken... <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":-)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1979078</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1979078</guid><dc:creator><![CDATA[bandchef]]></dc:creator><pubDate>Thu, 11 Nov 2010 17:16:04 GMT</pubDate></item><item><title><![CDATA[Reply to switch Anweisung? on Thu, 11 Nov 2010 17:28:41 GMT]]></title><description><![CDATA[<p>Joa ^^ Ich würd eher sagen, dass das der Aufgabe seine Sinnlosigkeit nimmt, aber oke :p</p>
<p>Viel Spaß beim Lösen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1979085</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1979085</guid><dc:creator><![CDATA[Felixxx]]></dc:creator><pubDate>Thu, 11 Nov 2010 17:28:41 GMT</pubDate></item><item><title><![CDATA[Reply to switch Anweisung? on Thu, 11 Nov 2010 17:39:35 GMT]]></title><description><![CDATA[<p>Es wäre auf jeden Fall sinnvoll das switch zeug in eine funktion (zB calc()) zu unterteilen. Ich hab mir es irgendwie angewöhnt alles außerhalb von main() und sogar außerhalb von main.cpp zu schreiben. So habe ich in main() zB nur: <code>MeinKern *kern = new MeinKern(); kern-&gt;start();</code> . Ich wies, das ist komisch... <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="🙄"
    /></p>
<p>(vv <em>signatur gucken</em> vv)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1979086</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1979086</guid><dc:creator><![CDATA[lk]]></dc:creator><pubDate>Thu, 11 Nov 2010 17:39:35 GMT</pubDate></item><item><title><![CDATA[Reply to switch Anweisung? on Thu, 11 Nov 2010 17:44:56 GMT]]></title><description><![CDATA[<p>lk schrieb:</p>
<blockquote>
<p>Es wäre auf jeden Fall sinnvoll das switch zeug in eine funktion (zB calc()) zu unterteilen. Ich hab mir es irgendwie angewöhnt alles außerhalb von main() und sogar außerhalb von main.cpp zu schreiben. So habe ich in main() zB nur: <code>MeinKern *kern = new MeinKern(); kern-&gt;start();</code> . Ich wies, das ist komisch... <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="🙄"
    /></p>
</blockquote>
<p>Das wird noch.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1979088</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1979088</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Thu, 11 Nov 2010 17:44:56 GMT</pubDate></item><item><title><![CDATA[Reply to switch Anweisung? on Fri, 12 Nov 2010 18:01:06 GMT]]></title><description><![CDATA[<p>Hi Leute!</p>
<p>Ihr kennt ja jetzt meine Aufgabe. Ich hab aber trotzdem irgendwie Probleme mit dem Verständnis der Aufgabe. Das liest sich für micht so, dass wenn Schritt 4 (also das Anzeigen des Ergebnisses) vorbei ist dann noch weitere Eingaben (ich find das sehr ungenau angegeben... was sind diese weiteren Eingaben?) machen darf. Das ist mein erstes Problem. Gut man darf weitere Eingaben MUSS aber anscheinend nicht. Dann geht's weiter bei Schritt 5. Der ist klar. Schritt 6 ist mir unklar. Eingabe einer Zahl. Wieder so ungenau. Welche Zahl meint er denn jetzt? Die erste oder die zweite? Vor allem die Eingabe einer Zahl macht doch nicht so viel Sinn, da ich ja dann bei der nächsten Rechenoperation die neue eingegebene Zahl mit der alten Zahl von ganz von Anfang mit dem neuen Operator verrechne... Schritt 7 ist klar, ich soll einfach wieder holen. Meine wahrscheinlich noch fehlerhaftes Programm seht ihr unten:</p>
<pre><code class="language-cpp">#include&lt;iostream&gt;
using namespace std;

int main()
{
char op;
int zahl1, zahl2, wzahl, erg, quit;

cout &lt;&lt; &quot;Zahl 1 eingeben: &quot;;
cin &gt;&gt; zahl1;

do
{
cout &lt;&lt; endl &lt;&lt; &quot;Operator eingeben (moeglicher Operator: +, -, *, / oder %): &quot;;
cin &gt;&gt; op;

cout &lt;&lt; endl &lt;&lt; &quot;Zahl 2 eingeben: &quot;;
cin &gt;&gt; zahl2;

switch (op)
{
case 43:
     cout &lt;&lt; &quot;Sie befinden sich in Addition&quot; &lt;&lt; endl;
     erg = zahl1 + zahl2;
     cout &lt;&lt; &quot;Ergebnis der Addition: &quot; &lt;&lt; erg &lt;&lt; endl;
     break;

case 45:
     cout &lt;&lt; &quot;Sie befinden sich in Subtraktion&quot; &lt;&lt; endl;
     erg = zahl1 - zahl2;
     cout &lt;&lt; &quot;Ergebnis der Subtraktion: &quot; &lt;&lt; erg &lt;&lt; endl;
     break;

case 42:
     cout &lt;&lt; &quot;Sie befinden sich in Multiplikation&quot; &lt;&lt; endl;
     erg = zahl1 * zahl2;
     cout &lt;&lt; &quot;Ergebnis der Multiplikation: &quot; &lt;&lt; erg &lt;&lt; endl;
     break;

case 47:
     cout &lt;&lt; &quot;Sie befinden sich in Division&quot; &lt;&lt; endl &lt;&lt; endl;
     erg = zahl1 / zahl2;
     cout &lt;&lt; &quot;Ergebnis der Division: &quot; &lt;&lt; erg &lt;&lt; endl;
     break;

case 37:
     cout &lt;&lt; &quot;Sie befinden sich in Modulo&quot; &lt;&lt; endl &lt;&lt; endl;
     erg = zahl1 % zahl2;
     cout &lt;&lt; &quot;Ergebnis von Modulo: &quot; &lt;&lt; erg &lt;&lt; endl;
     break;

default:
        cout &lt;&lt; &quot;Auf wiedersehen!&quot; &lt;&lt; endl;
        break;
}
}while(op != 113);

system(&quot;pause&quot;);
return 0;   
}
</code></pre>
<p>Wie seht ihr die Aufgabe? Ist die Aufgabe ungenau gestellt, oder bin ich einfach zu blöd/dumm/unerfahren oder für die Informatik nicht geeignet um das kapieren?</p>
<p>Danke!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1979621</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1979621</guid><dc:creator><![CDATA[bandchef]]></dc:creator><pubDate>Fri, 12 Nov 2010 18:01:06 GMT</pubDate></item><item><title><![CDATA[Reply to switch Anweisung? on Fri, 12 Nov 2010 18:11:10 GMT]]></title><description><![CDATA[<p>Ich würde sagen, dass du das Ergebnis was du bekommst weiter verwenden sollst.<br />
Das ist eigentlich ziemlich unmissverständlich formuliert und macht auch den meisten Sinn, weil man damit einem Taschenrechner sehr nahe kommt...<br />
Z.B.:<br />
4+4=8<br />
Eingabe von -2:<br />
8-2=6<br />
Eingabe von <em>4:<br />
6</em>4=24<br />
usw.</p>
<p>Schreib statt</p>
<pre><code class="language-cpp">case 42
</code></pre>
<p>lieber</p>
<pre><code class="language-cpp">case '*'
</code></pre>
<p>damit sofort klar ist das du ein char vergleichen möchtest und nicht einen int, zudem muss man nicht die ascii-Zeichen raten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1979628</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1979628</guid><dc:creator><![CDATA[JaykopX]]></dc:creator><pubDate>Fri, 12 Nov 2010 18:11:10 GMT</pubDate></item><item><title><![CDATA[Reply to switch Anweisung? on Sat, 13 Nov 2010 14:12:19 GMT]]></title><description><![CDATA[<p>Also, die Taschenrechnerfunktion geht jetzt eigenlich schon mal und zwar so wie du geschrieben hast, bzw. wie es die Aufgabe in der Tat verlangt. Das einzige Problem was ich jetzt noch habe ist, dass ich nicht recht weiß, wie ich die Sache mit dem &quot;Quit&quot; hinbekommen soll. Wenn ich mich nun bei Schritt 5 der Aufgabenstellung befinde und anstatt einen Operator die Taste &quot;q&quot; drücke, dann kommt trotzdem immer erst noch der darauffolgende Schritt &quot;Zahl2 eingeben: &quot; und dann erst der default Fall und erst dann wird die do-while-Schleife beendet, da dann die Bedingung nicht mehr erfüllt ist. Ich möchte aber, dass wenn ich bei Schritt 5 die Taste &quot;q&quot; drücke er mir SOFORT in den default-Fall springt und die do-while-Schleife beendet wird. Hier mein CODE:</p>
<pre><code class="language-cpp">#include&lt;iostream&gt;
using namespace std;

int main()
{
char op;
int zahl1, zahl2, erg, quit;

cout &lt;&lt; &quot;Zahl 1 eingeben: &quot;;
cin &gt;&gt; zahl1;

do
{
cout &lt;&lt; endl &lt;&lt; &quot;Operator eingeben (moeglicher Operator: +, -, *, / oder %): &quot;;
cin &gt;&gt; op;

cout &lt;&lt; endl &lt;&lt; &quot;Zahl 2 eingeben: &quot;;
cin &gt;&gt; zahl2;

switch (op)
{
case '+':
     cout &lt;&lt; &quot;Sie befinden sich in Addition&quot; &lt;&lt; endl;
     erg = zahl1 + zahl2;
     zahl1 = erg;
     cout &lt;&lt; &quot;Ergebnis der Addition: &quot; &lt;&lt; erg &lt;&lt; endl;
     break;

case '-':
     cout &lt;&lt; &quot;Sie befinden sich in Subtraktion&quot; &lt;&lt; endl;
     erg = zahl1 - zahl2;
     zahl1 = erg;
     cout &lt;&lt; &quot;Ergebnis der Subtraktion: &quot; &lt;&lt; erg &lt;&lt; endl;
     break;

case '*':
     cout &lt;&lt; &quot;Sie befinden sich in Multiplikation&quot; &lt;&lt; endl;
     erg = zahl1 * zahl2;
     zahl1 = erg;
     cout &lt;&lt; &quot;Ergebnis der Multiplikation: &quot; &lt;&lt; erg &lt;&lt; endl;
     break;

case '/':
     cout &lt;&lt; &quot;Sie befinden sich in Division&quot; &lt;&lt; endl &lt;&lt; endl;
     erg = zahl1 / zahl2;
     zahl1 = erg;
     cout &lt;&lt; &quot;Ergebnis der Division: &quot; &lt;&lt; erg &lt;&lt; endl;
     break;

case '%':
     cout &lt;&lt; &quot;Sie befinden sich in Modulo&quot; &lt;&lt; endl &lt;&lt; endl;
     erg = zahl1 % zahl2;
     zahl1 = erg;
     cout &lt;&lt; &quot;Ergebnis von Modulo: &quot; &lt;&lt; erg &lt;&lt; endl;
     break;

default:
        cout &lt;&lt; &quot;Auf wiedersehen!&quot; &lt;&lt; endl;
        break;
}
}while(op != 'q');

system(&quot;pause&quot;);
return 0;   
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1979897</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1979897</guid><dc:creator><![CDATA[bandchef]]></dc:creator><pubDate>Sat, 13 Nov 2010 14:12:19 GMT</pubDate></item><item><title><![CDATA[Reply to switch Anweisung? on Sat, 13 Nov 2010 14:28:55 GMT]]></title><description><![CDATA[<p>So, ich glaub ich hab die Lösung meines Problems nun selber hinbekommen. Vielleicht seid ihr so nett und guckt mal drüber ob das so der Aufgabe entspricht, bzw. ob ihr das euch auch so vorgestellt habt... Danke!</p>
<p>Hier der neue Code:</p>
<pre><code class="language-cpp">#include&lt;iostream&gt;
using namespace std;

int main()
{
char op;
int zahl1, zahl2, erg, quit;

cout &lt;&lt; &quot;Zahl 1 eingeben: &quot;;
cin &gt;&gt; zahl1;

do
{
cout &lt;&lt; endl &lt;&lt; &quot;Operator eingeben (moeglicher Operator: +, -, *, /, % oder q fuer Quit): &quot;;
cin &gt;&gt; op;

switch(op)
{
case '+':
     cout &lt;&lt; endl &lt;&lt; &quot;Sie befinden sich in Addition&quot; &lt;&lt; endl;
     cout &lt;&lt; endl &lt;&lt; &quot;Zahl 2 eingeben: &quot;;
     cin &gt;&gt; zahl2;
     erg = zahl1 + zahl2;
     zahl1 = erg;
     cout &lt;&lt; &quot;Ergebnis der Addition: &quot; &lt;&lt; erg &lt;&lt; endl;
     break;

case '-':
     cout &lt;&lt; endl &lt;&lt; &quot;Sie befinden sich in Subtraktion&quot; &lt;&lt; endl;
     cout &lt;&lt; endl &lt;&lt; &quot;Zahl 2 eingeben: &quot;;
     cin &gt;&gt; zahl2;
     erg = zahl1 - zahl2;
     zahl1 = erg;
     cout &lt;&lt; &quot;Ergebnis der Subtraktion: &quot; &lt;&lt; erg &lt;&lt; endl;
     break;

case '*':
     cout &lt;&lt; endl &lt;&lt; &quot;Sie befinden sich in Multiplikation&quot; &lt;&lt; endl;
     cout &lt;&lt; endl &lt;&lt; &quot;Zahl 2 eingeben: &quot;;
     cin &gt;&gt; zahl2;
     erg = zahl1 * zahl2;
     zahl1 = erg;
     cout &lt;&lt; &quot;Ergebnis der Multiplikation: &quot; &lt;&lt; erg &lt;&lt; endl;
     break;

case '/':
     cout &lt;&lt; endl &lt;&lt; &quot;Sie befinden sich in Division&quot; &lt;&lt; endl &lt;&lt; endl;
     cout &lt;&lt; endl &lt;&lt; &quot;Zahl 2 eingeben: &quot;;
     cin &gt;&gt; zahl2;
     erg = zahl1 / zahl2;
     zahl1 = erg;
     cout &lt;&lt; &quot;Ergebnis der Division: &quot; &lt;&lt; erg &lt;&lt; endl;
     break;

case '%':
     cout &lt;&lt; endl &lt;&lt; &quot;Sie befinden sich in Modulo&quot; &lt;&lt; endl &lt;&lt; endl;
     cout &lt;&lt; endl &lt;&lt; &quot;Zahl 2 eingeben: &quot;;
     cin &gt;&gt; zahl2;
     erg = zahl1 % zahl2;
     zahl1 = erg;
     cout &lt;&lt; &quot;Ergebnis von Modulo: &quot; &lt;&lt; erg &lt;&lt; endl;
     break;

default:
        cout &lt;&lt; endl &lt;&lt; &quot;Auf wiedersehen!&quot; &lt;&lt; endl;
        break;
}
}while(op != 'q');

system(&quot;pause&quot;);
return 0;   
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1979907</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1979907</guid><dc:creator><![CDATA[bandchef]]></dc:creator><pubDate>Sat, 13 Nov 2010 14:28:55 GMT</pubDate></item><item><title><![CDATA[Reply to switch Anweisung? on Sat, 13 Nov 2010 15:13:07 GMT]]></title><description><![CDATA[<p>Nachdem ich 3 mal meine Meinung geändert habe bin ich zu dem Schluss gekommen, dass das Programm genau das macht was gefordert ist <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="👍"
    />.<br />
Nur wenn du was anderes als q(oder operator) eingibst, dann sagt der Taschenrechner &quot;Auf Wiedersehen&quot; beendet aber nicht.</p>
<p>Die Variable quit ist überflüssig und Einrückungen könnten noch optimiert werden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1979925</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1979925</guid><dc:creator><![CDATA[JaykopX]]></dc:creator><pubDate>Sat, 13 Nov 2010 15:13:07 GMT</pubDate></item></channel></rss>