<?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[Rundene einer Dezimalzahlq]]></title><description><![CDATA[<p>Folgendes Programm enthält mehere switch-Anweisungen.<br />
Unter Punkt 'r' soll eine Dezimalzahl gerundet werden.<br />
Das Programm gibt aber nicht die gerundete Zahl aus.<br />
Bei 3.3 kommt 3 raus bei 3.8 kommt wieder 3<br />
raus. Das selbe gilt auch für negative Zahlen.<br />
Könnte mir mal jemand bitte weiterhelfen.<br />
Vielen Dank!</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
using namespace std;

int main ()
{
    sprungpunkt:

    char befehl;

    cout &lt;&lt; endl;
    cout &lt;&lt; &quot; Ausgabe des vollstaendigen Zeichensatzes   &lt; a, A&gt; &quot; &lt;&lt; endl;
    cout &lt;&lt; &quot; Runden einer Dezimalzahl                   &lt; r &gt;   &quot; &lt;&lt; endl;
    cout &lt;&lt; &quot; Umwandlung von Buchstaben (klein&lt;-&gt;gross)  &lt; u &gt;   &quot; &lt;&lt; endl;
    cout &lt;&lt; &quot; Beenden des Programmes                     &lt; b, x&gt; &quot; &lt;&lt; endl;

    cout &lt;&lt; &quot; Ihre Eingabe : &quot;;
    cin  &gt;&gt; befehl;

    switch ( befehl )
    {
           case 'a':
           case 'A':
                {
                    cout &lt;&lt; &quot; Der vollständige Zeichensatz wird ausgegeben &quot; &lt;&lt; endl;
                    for ( int i =-128; i&lt;=127; i++)
                    {
                        putchar(i);
                        cout &lt;&lt; endl;
                    }
                break;
                }
           case 'r':
                {
                    int zahl;
                    cout &lt;&lt; &quot; Runden einer Dezimalzahl &quot; &lt;&lt; endl;
                    cout &lt;&lt; &quot; Bitte geben Sie eine Zahl ein: &quot; &lt;&lt; endl;
                    cin &gt;&gt; zahl;

                    if (zahl&lt;0)
                       zahl= zahl-0.5;
                    else 
                         zahl=zahl+0.5;
                    cout &lt;&lt; int (zahl) &lt;&lt; endl;
                break;
                }
           case 'u':
                {
                    cout &lt;&lt; &quot; Umwandlung von Gross- in Kleinbuchstaben &quot; &lt;&lt; endl;
                    char abc;
                    cout &lt;&lt; &quot; Bitte geben Sie einen Buchstaben ein &quot; &lt;&lt; endl;
                    cin &gt;&gt; abc;

                    if (abc &lt; 'A' &amp;&amp; abc &gt; 'a'  )
                    {
                       cout &lt;&lt; &quot; Ungültige Eingabe &quot; &lt;&lt; endl;
                    }
                    if (abc &gt;='A' &amp;&amp; abc &lt;= 'Z')
                       {
                       abc= abc + 32;
                       cout &lt;&lt; abc &lt;&lt; endl;
                       }
                     else if (abc &gt;='a' &amp;&amp;  abc &lt;= 'z')
                       {
                      abc= abc -32;
                      cout &lt;&lt; abc &lt;&lt; endl;
                       }
                    break;
                    }
             case 'b':
             case 'x':
                  {
                      cout &lt;&lt; &quot; Ende &quot; &lt;&lt; endl;
                   break;
                  }
            goto sprungpunkt;
            }
            return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/293080/rundene-einer-dezimalzahlq</link><generator>RSS for Node</generator><lastBuildDate>Sun, 16 Aug 2026 13:10:59 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/293080.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 25 Sep 2011 11:34:54 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Rundene einer Dezimalzahlq on Sun, 25 Sep 2011 11:34:54 GMT]]></title><description><![CDATA[<p>Folgendes Programm enthält mehere switch-Anweisungen.<br />
Unter Punkt 'r' soll eine Dezimalzahl gerundet werden.<br />
Das Programm gibt aber nicht die gerundete Zahl aus.<br />
Bei 3.3 kommt 3 raus bei 3.8 kommt wieder 3<br />
raus. Das selbe gilt auch für negative Zahlen.<br />
Könnte mir mal jemand bitte weiterhelfen.<br />
Vielen Dank!</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
using namespace std;

int main ()
{
    sprungpunkt:

    char befehl;

    cout &lt;&lt; endl;
    cout &lt;&lt; &quot; Ausgabe des vollstaendigen Zeichensatzes   &lt; a, A&gt; &quot; &lt;&lt; endl;
    cout &lt;&lt; &quot; Runden einer Dezimalzahl                   &lt; r &gt;   &quot; &lt;&lt; endl;
    cout &lt;&lt; &quot; Umwandlung von Buchstaben (klein&lt;-&gt;gross)  &lt; u &gt;   &quot; &lt;&lt; endl;
    cout &lt;&lt; &quot; Beenden des Programmes                     &lt; b, x&gt; &quot; &lt;&lt; endl;

    cout &lt;&lt; &quot; Ihre Eingabe : &quot;;
    cin  &gt;&gt; befehl;

    switch ( befehl )
    {
           case 'a':
           case 'A':
                {
                    cout &lt;&lt; &quot; Der vollständige Zeichensatz wird ausgegeben &quot; &lt;&lt; endl;
                    for ( int i =-128; i&lt;=127; i++)
                    {
                        putchar(i);
                        cout &lt;&lt; endl;
                    }
                break;
                }
           case 'r':
                {
                    int zahl;
                    cout &lt;&lt; &quot; Runden einer Dezimalzahl &quot; &lt;&lt; endl;
                    cout &lt;&lt; &quot; Bitte geben Sie eine Zahl ein: &quot; &lt;&lt; endl;
                    cin &gt;&gt; zahl;

                    if (zahl&lt;0)
                       zahl= zahl-0.5;
                    else 
                         zahl=zahl+0.5;
                    cout &lt;&lt; int (zahl) &lt;&lt; endl;
                break;
                }
           case 'u':
                {
                    cout &lt;&lt; &quot; Umwandlung von Gross- in Kleinbuchstaben &quot; &lt;&lt; endl;
                    char abc;
                    cout &lt;&lt; &quot; Bitte geben Sie einen Buchstaben ein &quot; &lt;&lt; endl;
                    cin &gt;&gt; abc;

                    if (abc &lt; 'A' &amp;&amp; abc &gt; 'a'  )
                    {
                       cout &lt;&lt; &quot; Ungültige Eingabe &quot; &lt;&lt; endl;
                    }
                    if (abc &gt;='A' &amp;&amp; abc &lt;= 'Z')
                       {
                       abc= abc + 32;
                       cout &lt;&lt; abc &lt;&lt; endl;
                       }
                     else if (abc &gt;='a' &amp;&amp;  abc &lt;= 'z')
                       {
                      abc= abc -32;
                      cout &lt;&lt; abc &lt;&lt; endl;
                       }
                    break;
                    }
             case 'b':
             case 'x':
                  {
                      cout &lt;&lt; &quot; Ende &quot; &lt;&lt; endl;
                   break;
                  }
            goto sprungpunkt;
            }
            return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2123443</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2123443</guid><dc:creator><![CDATA[Reeko25]]></dc:creator><pubDate>Sun, 25 Sep 2011 11:34:54 GMT</pubDate></item><item><title><![CDATA[Reply to Rundene einer Dezimalzahlq on Sun, 25 Sep 2011 11:42:52 GMT]]></title><description><![CDATA[<p>zahl ist ein int, sollte wohl eher float/double sein.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2123446</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2123446</guid><dc:creator><![CDATA[Caligulaminus]]></dc:creator><pubDate>Sun, 25 Sep 2011 11:42:52 GMT</pubDate></item><item><title><![CDATA[Reply to Rundene einer Dezimalzahlq on Sun, 25 Sep 2011 12:10:28 GMT]]></title><description><![CDATA[<p>Und noch ein paar Hinweise:<br />
- deine Bedingung &quot;if (abc &lt; 'A' &amp;&amp; abc &gt; 'a' )&quot; wird bei dem üblichen ASCII-Zeichensatz immer 'false' sein<br />
- benutze zum Umwandeln besser tolower() und toupper() (aus &lt;cctype&gt;)<br />
- goto wird (hier im Forum) auch nicht so gern gesehen - nimm besser eine while-Schleife</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2123456</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2123456</guid><dc:creator><![CDATA[Th69]]></dc:creator><pubDate>Sun, 25 Sep 2011 12:10:28 GMT</pubDate></item><item><title><![CDATA[Reply to Rundene einer Dezimalzahlq on Sun, 25 Sep 2011 12:24:51 GMT]]></title><description><![CDATA[<p>Th69 schrieb:</p>
<blockquote>
<p>- goto wird (hier im Forum) auch nicht so gern gesehen - nimm besser eine while-Schleife</p>
</blockquote>
<p>while(true)-Schleifen sind (hier im Forum) auch nicht gern gesehen - nimm besser eine <code>for(;;</code>  <code>)</code> -Schleife.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2123461</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2123461</guid><dc:creator><![CDATA[forever]]></dc:creator><pubDate>Sun, 25 Sep 2011 12:24:51 GMT</pubDate></item><item><title><![CDATA[Reply to Rundene einer Dezimalzahlq on Sun, 25 Sep 2011 14:01:16 GMT]]></title><description><![CDATA[<p>forever schrieb:</p>
<blockquote>
<p>Th69 schrieb:</p>
<blockquote>
<p>- goto wird (hier im Forum) auch nicht so gern gesehen - nimm besser eine while-Schleife</p>
</blockquote>
<p>while(true)-Schleifen sind (hier im Forum) auch nicht gern gesehen - nimm besser eine <code>for(;;</code>  <code>)</code> -Schleife.</p>
</blockquote>
<p>for(;;)-Schleifen sind (hier im Forum) auch nicht gern gesehen - nimm besser eine Schleife mit sinnvoller Abbruchbedingung.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2123495</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2123495</guid><dc:creator><![CDATA[Ethon]]></dc:creator><pubDate>Sun, 25 Sep 2011 14:01:16 GMT</pubDate></item><item><title><![CDATA[Reply to Rundene einer Dezimalzahlq on Sun, 25 Sep 2011 17:44:49 GMT]]></title><description><![CDATA[<p>Ethon schrieb:</p>
<blockquote>
<p>forever schrieb:</p>
<blockquote>
<p>Th69 schrieb:</p>
<blockquote>
<p>- goto wird (hier im Forum) auch nicht so gern gesehen - nimm besser eine while-Schleife</p>
</blockquote>
<p>while(true)-Schleifen sind (hier im Forum) auch nicht gern gesehen - nimm besser eine <code>for(;;</code>  <code>)</code> -Schleife.</p>
</blockquote>
<p>for(;;)-Schleifen sind (hier im Forum) auch nicht gern gesehen - nimm besser eine Schleife mit sinnvoller Abbruchbedingung.</p>
</blockquote>
<p>Schleifen mit sinnvoller Abbruchbedingung sind (hier im Forum) auch nicht gern gesehen - nimm besser garkeine Schleifen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2123548</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2123548</guid><dc:creator><![CDATA[Schleifenmaster]]></dc:creator><pubDate>Sun, 25 Sep 2011 17:44:49 GMT</pubDate></item><item><title><![CDATA[Reply to Rundene einer Dezimalzahlq on Sun, 25 Sep 2011 17:54:06 GMT]]></title><description><![CDATA[<p>Schleifenmaster schrieb:</p>
<blockquote>
<p>Ethon schrieb:</p>
<blockquote>
<p>forever schrieb:</p>
<blockquote>
<p>Th69 schrieb:</p>
<blockquote>
<p>- goto wird (hier im Forum) auch nicht so gern gesehen - nimm besser eine while-Schleife</p>
</blockquote>
<p>while(true)-Schleifen sind (hier im Forum) auch nicht gern gesehen - nimm besser eine <code>for(;;</code>  <code>)</code> -Schleife.</p>
</blockquote>
<p>for(;;)-Schleifen sind (hier im Forum) auch nicht gern gesehen - nimm besser eine Schleife mit sinnvoller Abbruchbedingung.</p>
</blockquote>
<p>Schleifen mit sinnvoller Abbruchbedingung sind (hier im Forum) auch nicht gern gesehen - nimm besser garkeine Schleifen.</p>
</blockquote>
<p>Fehlerhafte Programme sind (hier im Forum) auch nicht gern gesehen - nimm besser Rekursion.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2123551</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2123551</guid><dc:creator><![CDATA[Recurrentmaster]]></dc:creator><pubDate>Sun, 25 Sep 2011 17:54:06 GMT</pubDate></item><item><title><![CDATA[Reply to Rundene einer Dezimalzahlq on Sun, 25 Sep 2011 18:17:15 GMT]]></title><description><![CDATA[<p>Recurrentmaster schrieb:</p>
<blockquote>
<p>Schleifenmaster schrieb:</p>
<blockquote>
<p>Ethon schrieb:</p>
<blockquote>
<p>forever schrieb:</p>
<blockquote>
<p>Th69 schrieb:</p>
<blockquote>
<p>- goto wird (hier im Forum) auch nicht so gern gesehen - nimm besser eine while-Schleife</p>
</blockquote>
<p>while(true)-Schleifen sind (hier im Forum) auch nicht gern gesehen - nimm besser eine <code>for(;;</code>  <code>)</code> -Schleife.</p>
</blockquote>
<p>for(;;)-Schleifen sind (hier im Forum) auch nicht gern gesehen - nimm besser eine Schleife mit sinnvoller Abbruchbedingung.</p>
</blockquote>
<p>Schleifen mit sinnvoller Abbruchbedingung sind (hier im Forum) auch nicht gern gesehen - nimm besser garkeine Schleifen.</p>
</blockquote>
<p>Fehlerhafte Programme sind (hier im Forum) auch nicht gern gesehen - nimm besser Rekursion.</p>
</blockquote>
<p>Unsinnige Beiträge sind (hier im Forum) auch nicht gerne gesehen - schreib lieber was konstruktives.</p>
<p>Oder anders: spätestens sein &quot;Schleifenmaster&quot; wurde das Spiel absurd, also bleibt bitte in der Nähe des Themas.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2123563</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2123563</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Sun, 25 Sep 2011 18:17:15 GMT</pubDate></item><item><title><![CDATA[Reply to Rundene einer Dezimalzahlq on Mon, 26 Sep 2011 15:17:54 GMT]]></title><description><![CDATA[<p>Um Zahlen auf/abzurunden gibt es zwei nützliche Funktionen:</p>
<p>aufrunden: floor()<br />
abrunden: ceil()</p>
<p>Enthalten in &lt;cmath.h&gt;</p>
<p>...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2123931</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2123931</guid><dc:creator><![CDATA[Golfi1812]]></dc:creator><pubDate>Mon, 26 Sep 2011 15:17:54 GMT</pubDate></item><item><title><![CDATA[Reply to Rundene einer Dezimalzahlq on Mon, 26 Sep 2011 15:18:50 GMT]]></title><description><![CDATA[<p>Golfi1812 schrieb:</p>
<blockquote>
<p>Enthalten in &lt;cmath.h&gt;</p>
</blockquote>
<p>Äh, nö. Fast richtig. &lt;cmath&gt;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2123932</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2123932</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Mon, 26 Sep 2011 15:18:50 GMT</pubDate></item></channel></rss>