<?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[Fehlersuche bei code mit switch]]></title><description><![CDATA[<p>Hallo Leute, ich kann in meinem Programm einfach nicht den Fehler finden. Hätte einer von euch eine Idee?<br />
Zur Aufagbe: Es sollen nacheinander 2 Zahlen eingegeben werden (von 1-3) und die daraus kombinierte Zahl z.B. 22 soll dann bei der Ausgabe &quot;Zweiundzwanzig&quot; stehen.</p>
<pre><code>#include &lt;iostream&gt;
using namespace std;

int main() {
    unsigned short a,b;
    cout &lt;&lt; &quot;Erste Ziffer (1..3): &quot;;
    cin &gt;&gt; a;
    cout &lt;&lt; &quot;Zweite Ziffer (1..3): &quot;;
    cin &gt;&gt; b;

switch (a) {
        case '1' :
            switch (b) {
                case '1' :
                    cout &lt;&lt; &quot;Elf&quot;;
                break;
                case '2' :
                    cout &lt;&lt; &quot;Zwoelf&quot;;
                break;
                case '3' :
                    cout &lt;&lt; &quot;Dreizehn&quot;;
                break;
            }
        break;
        case '2' :
            switch (b) {
                case '1' :
                    cout &lt;&lt; &quot;Einundzwanzig&quot;;
                break;
                case '2' :
                    cout &lt;&lt; &quot;Zweiundzwanzig&quot;;
                break;
                case '3' :
                    cout &lt;&lt; &quot;Dreiundzwanzig&quot;;
                break;
            }
        break;
        case '3' :
            switch (b) {
                case '1' :
                    cout &lt;&lt; &quot;Einunddreissig&quot;;
                break;
                case '2' :
                    cout &lt;&lt; &quot;Zweiunddreissig&quot;;
                break;
                case '3' :
                    cout &lt;&lt; &quot;Dreiunddreissig&quot;;
                break;
            }
        break;

        default: cout &lt;&lt; &quot;Unzulaessige Eingabe, Programm beendet&quot;;
        break;
    }
    cout &lt;&lt; endl;

return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/337349/fehlersuche-bei-code-mit-switch</link><generator>RSS for Node</generator><lastBuildDate>Sat, 18 Apr 2026 04:35:19 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/337349.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 26 Mar 2016 18:22:03 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Fehlersuche bei code mit switch on Sat, 26 Mar 2016 18:22:03 GMT]]></title><description><![CDATA[<p>Hallo Leute, ich kann in meinem Programm einfach nicht den Fehler finden. Hätte einer von euch eine Idee?<br />
Zur Aufagbe: Es sollen nacheinander 2 Zahlen eingegeben werden (von 1-3) und die daraus kombinierte Zahl z.B. 22 soll dann bei der Ausgabe &quot;Zweiundzwanzig&quot; stehen.</p>
<pre><code>#include &lt;iostream&gt;
using namespace std;

int main() {
    unsigned short a,b;
    cout &lt;&lt; &quot;Erste Ziffer (1..3): &quot;;
    cin &gt;&gt; a;
    cout &lt;&lt; &quot;Zweite Ziffer (1..3): &quot;;
    cin &gt;&gt; b;

switch (a) {
        case '1' :
            switch (b) {
                case '1' :
                    cout &lt;&lt; &quot;Elf&quot;;
                break;
                case '2' :
                    cout &lt;&lt; &quot;Zwoelf&quot;;
                break;
                case '3' :
                    cout &lt;&lt; &quot;Dreizehn&quot;;
                break;
            }
        break;
        case '2' :
            switch (b) {
                case '1' :
                    cout &lt;&lt; &quot;Einundzwanzig&quot;;
                break;
                case '2' :
                    cout &lt;&lt; &quot;Zweiundzwanzig&quot;;
                break;
                case '3' :
                    cout &lt;&lt; &quot;Dreiundzwanzig&quot;;
                break;
            }
        break;
        case '3' :
            switch (b) {
                case '1' :
                    cout &lt;&lt; &quot;Einunddreissig&quot;;
                break;
                case '2' :
                    cout &lt;&lt; &quot;Zweiunddreissig&quot;;
                break;
                case '3' :
                    cout &lt;&lt; &quot;Dreiunddreissig&quot;;
                break;
            }
        break;

        default: cout &lt;&lt; &quot;Unzulaessige Eingabe, Programm beendet&quot;;
        break;
    }
    cout &lt;&lt; endl;

return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2491539</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2491539</guid><dc:creator><![CDATA[Gast1010]]></dc:creator><pubDate>Sat, 26 Mar 2016 18:22:03 GMT</pubDate></item><item><title><![CDATA[Reply to Fehlersuche bei code mit switch on Sat, 26 Mar 2016 18:31:55 GMT]]></title><description><![CDATA[<pre><code>#include &lt;iostream&gt;
using namespace std;

int main() {
    unsigned short a,b;  // und warum nimmst du dann weiter unten char statt short?
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2491540</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2491540</guid><dc:creator><![CDATA[f.-th.]]></dc:creator><pubDate>Sat, 26 Mar 2016 18:31:55 GMT</pubDate></item><item><title><![CDATA[Reply to Fehlersuche bei code mit switch on Sat, 26 Mar 2016 21:02:10 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">char a, b;
  cin &gt;&gt; a; cin &gt;&gt; b;
  string Einer[4] = { &quot;&quot;, &quot;Ein&quot;, &quot;Zwei&quot;, &quot;Drei&quot; };
  string Zehner[4] = { &quot;&quot;, &quot;&quot;, &quot;zwanzig&quot;, &quot;dreissig&quot; };
  string s;
  if (a == '1')
    switch(b)
    {
      case '1': s = &quot;Elf&quot;; break;
      case '2': s = &quot;Zwoelf&quot;; break;
      case '3': s = &quot;Dreizehn&quot;; break;
    }
  else
    s = Einer[b-'0'] + &quot;und&quot; + Zehner[a-'0'];
  cout &lt;&lt; s &lt;&lt; endl;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2491549</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2491549</guid><dc:creator><![CDATA[klassenmethode]]></dc:creator><pubDate>Sat, 26 Mar 2016 21:02:10 GMT</pubDate></item><item><title><![CDATA[Reply to Fehlersuche bei code mit switch on Tue, 29 Mar 2016 11:05:17 GMT]]></title><description><![CDATA[<p>Im Prinzip ist dein Ansatz genau richtig so, dein einziger Fehler liegt bei case<br />
da vergleichst du nämlich Integer (1-3) mit chars ('1', '2', '3'), hier würde dann von int zu char implizit gecastet werden und das führt nicht zu dem Ergebnis, welches du haben willst.</p>
<p>Alt</p>
<pre><code>switch (a) {
	case '1':
		switch (b) {
		case '1':
			cout &lt;&lt; &quot;Elf&quot;;
			break;
		case '2':
			cout &lt;&lt; &quot;Zwoelf&quot;;
			break;
		case '3':
			cout &lt;&lt; &quot;Dreizehn&quot;;
			break;
		}
		break;
</code></pre>
<p>Neu</p>
<pre><code>switch (a) {
	case 1:
		switch (b) {
		case 1:
			cout &lt;&lt; &quot;Elf&quot;;
			break;
		case 2:
			cout &lt;&lt; &quot;Zwoelf&quot;;
			break;
		case 3:
			cout &lt;&lt; &quot;Dreizehn&quot;;
			break;
		}
		break;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2491752</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2491752</guid><dc:creator><![CDATA[Talon]]></dc:creator><pubDate>Tue, 29 Mar 2016 11:05:17 GMT</pubDate></item></channel></rss>