<?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[String aus Funktion]]></title><description><![CDATA[<p>Hi,</p>
<p>ich programmire noch nicht lange in c++ und habe ein kleines Problem:</p>
<p>Ich habe eine übungsaufgabe, in der eich ein Programm schreiben soll, dass den promillewert nach dem genuss verschiedener alkoholika in einer tabelle auflistet. Die Tabelle soll bei jedem getränk von 0,2 bis 2 Lieter, in schritten von 0,2 Lieter angezeitgt werden. Wie kann ich das machen, dass alles von einer Funktion berechnet wird (ARRAY!!)</p>
<p>Das ist mein bisheriger quellcode:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

using namespace std;

    char menu;
    int gewicht = 0;
    float volume = 0;
    float promille;
    float lieter = 2.0;
    int i; //Zählvariable
    float alc; //Var gibt die menge des reinen alkohols an

    float volbier()
    {
        volume = 0.06;

        while ( lieter &lt;= 2)
        {
            alc = lieter * volume;
            promille = alc / gewicht * 1000.0;
            lieter = lieter + 0.2;
            ++i;
        };

    return promille;

    };

int main()

{

    cout&lt;&lt;&quot;Drunken Monkey\nProgramm zum errechnen des Promille gehalts nach alkohol genuss\n\nMenue&quot;&lt;&lt;endl;

temp://GOTO.. nur vorläufig!

    cout&lt;&lt;&quot;1)Gewicht eingeben\n2)Tabelle Anzeigen\n3)Programm beenden&quot;&lt;&lt;endl;
    cin&gt;&gt;menu;

    if (menu =='1')
    {    cout&lt;&lt;&quot;Geben Sie ihr gewicht an: &quot;&lt;&lt;endl;
        cin&gt;&gt;gewicht;
        if (gewicht &lt; 45)
            cout&lt;&lt;&quot;Kein Alkohol für Kinder und Jugendliche!!!&quot;&lt;&lt;endl;
        goto temp; //GOTO.. nur vorläufig!
    };

    if (menu =='2')

    {
        cout&lt;&lt;&quot;Menge   Bier        Wein      Wodka     Stroh-Rum&quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; (l)       Promille Promille  Promille  Promille &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot;----------------------------------------------------- &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 0.2       &quot;&lt;&lt;volbier()&lt;&lt;&quot;                                             &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 0.3                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 0.4                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 0.5                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 0.6                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 0.7                                                  &quot;&lt;&lt;endl;  
        cout&lt;&lt;&quot; 0.8                                                  &quot;&lt;&lt;endl;  
        cout&lt;&lt;&quot; 0.9                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 1.0                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 1.1                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 1.2                                                  &quot;&lt;&lt;endl;  
        cout&lt;&lt;&quot; 1.3                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 1.4                                                  &quot;&lt;&lt;endl;  
        cout&lt;&lt;&quot; 1.5                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 1.6                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 1.7                                                  &quot;&lt;&lt;endl;    
        cout&lt;&lt;&quot; 1.8                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 1.9                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 2.0                                                  &quot;&lt;&lt;endl;  
    };

    if (menu =='3')

return 0;
};
</code></pre>
<p>Ausserdem würde ich gerne das doofe &quot;goto&quot; loswerden, hab das aber mit schleifen nicht hinbekommen..</p>
<p>Zur info: ich benutze Microsoft Visual C++ 6.0</p>
<p>danke für eure hilfe,<br />
Florian</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/123301/string-aus-funktion</link><generator>RSS for Node</generator><lastBuildDate>Sun, 23 Aug 2026 12:19:50 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/123301.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 14 Oct 2005 20:10:36 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to String aus Funktion on Fri, 14 Oct 2005 20:10:36 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>ich programmire noch nicht lange in c++ und habe ein kleines Problem:</p>
<p>Ich habe eine übungsaufgabe, in der eich ein Programm schreiben soll, dass den promillewert nach dem genuss verschiedener alkoholika in einer tabelle auflistet. Die Tabelle soll bei jedem getränk von 0,2 bis 2 Lieter, in schritten von 0,2 Lieter angezeitgt werden. Wie kann ich das machen, dass alles von einer Funktion berechnet wird (ARRAY!!)</p>
<p>Das ist mein bisheriger quellcode:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

using namespace std;

    char menu;
    int gewicht = 0;
    float volume = 0;
    float promille;
    float lieter = 2.0;
    int i; //Zählvariable
    float alc; //Var gibt die menge des reinen alkohols an

    float volbier()
    {
        volume = 0.06;

        while ( lieter &lt;= 2)
        {
            alc = lieter * volume;
            promille = alc / gewicht * 1000.0;
            lieter = lieter + 0.2;
            ++i;
        };

    return promille;

    };

int main()

{

    cout&lt;&lt;&quot;Drunken Monkey\nProgramm zum errechnen des Promille gehalts nach alkohol genuss\n\nMenue&quot;&lt;&lt;endl;

temp://GOTO.. nur vorläufig!

    cout&lt;&lt;&quot;1)Gewicht eingeben\n2)Tabelle Anzeigen\n3)Programm beenden&quot;&lt;&lt;endl;
    cin&gt;&gt;menu;

    if (menu =='1')
    {    cout&lt;&lt;&quot;Geben Sie ihr gewicht an: &quot;&lt;&lt;endl;
        cin&gt;&gt;gewicht;
        if (gewicht &lt; 45)
            cout&lt;&lt;&quot;Kein Alkohol für Kinder und Jugendliche!!!&quot;&lt;&lt;endl;
        goto temp; //GOTO.. nur vorläufig!
    };

    if (menu =='2')

    {
        cout&lt;&lt;&quot;Menge   Bier        Wein      Wodka     Stroh-Rum&quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; (l)       Promille Promille  Promille  Promille &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot;----------------------------------------------------- &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 0.2       &quot;&lt;&lt;volbier()&lt;&lt;&quot;                                             &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 0.3                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 0.4                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 0.5                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 0.6                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 0.7                                                  &quot;&lt;&lt;endl;  
        cout&lt;&lt;&quot; 0.8                                                  &quot;&lt;&lt;endl;  
        cout&lt;&lt;&quot; 0.9                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 1.0                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 1.1                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 1.2                                                  &quot;&lt;&lt;endl;  
        cout&lt;&lt;&quot; 1.3                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 1.4                                                  &quot;&lt;&lt;endl;  
        cout&lt;&lt;&quot; 1.5                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 1.6                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 1.7                                                  &quot;&lt;&lt;endl;    
        cout&lt;&lt;&quot; 1.8                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 1.9                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 2.0                                                  &quot;&lt;&lt;endl;  
    };

    if (menu =='3')

return 0;
};
</code></pre>
<p>Ausserdem würde ich gerne das doofe &quot;goto&quot; loswerden, hab das aber mit schleifen nicht hinbekommen..</p>
<p>Zur info: ich benutze Microsoft Visual C++ 6.0</p>
<p>danke für eure hilfe,<br />
Florian</p>
]]></description><link>https://www.c-plusplus.net/forum/post/892621</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/892621</guid><dc:creator><![CDATA[FlorianW]]></dc:creator><pubDate>Fri, 14 Oct 2005 20:10:36 GMT</pubDate></item><item><title><![CDATA[Reply to String aus Funktion on Fri, 14 Oct 2005 20:20:27 GMT]]></title><description><![CDATA[<p>He he, ich weiß nicht ob ich dir helfen kann wenn ich sowas sehe:</p>
<blockquote>
<pre><code class="language-cpp">if (menu =='2')

    {
        cout&lt;&lt;&quot;Menge   Bier        Wein      Wodka     Stroh-Rum&quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; (l)       Promille Promille  Promille  Promille &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot;----------------------------------------------------- &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 0.2       &quot;&lt;&lt;volbier()&lt;&lt;&quot;                                             &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 0.3                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 0.4                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 0.5                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 0.6                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 0.7                                                  &quot;&lt;&lt;endl;  
        cout&lt;&lt;&quot; 0.8                                                  &quot;&lt;&lt;endl;  
        cout&lt;&lt;&quot; 0.9                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 1.0                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 1.1                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 1.2                                                  &quot;&lt;&lt;endl;  
        cout&lt;&lt;&quot; 1.3                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 1.4                                                  &quot;&lt;&lt;endl;  
        cout&lt;&lt;&quot; 1.5                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 1.6                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 1.7                                                  &quot;&lt;&lt;endl;    
        cout&lt;&lt;&quot; 1.8                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 1.9                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 2.0                                                  &quot;&lt;&lt;endl;  
    };
</code></pre>
</blockquote>
<p>Eine Schleife hätte dir wohl einiges Copy und Paste erspart.<br />
Wieso überhaupt so viele Leerzeilen im Source, klemmt dein Enter?</p>
<blockquote>
<pre><code class="language-cpp">if (menu =='3')
</code></pre>
</blockquote>
<p>Und was macht das? Warten bis der Bildschirmschoner anspringt?</p>
<p>Dein goto könntest du so wegkriegen:</p>
<pre><code class="language-cpp">do {
  char c = menu();
  switch (c) {
    //mach was mit c
  };
} while (c!='4');  //Angenommen die Eingabe von 4 soll beenden
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/892624</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/892624</guid><dc:creator><![CDATA[GPC]]></dc:creator><pubDate>Fri, 14 Oct 2005 20:20:27 GMT</pubDate></item><item><title><![CDATA[Reply to String aus Funktion on Fri, 14 Oct 2005 20:49:15 GMT]]></title><description><![CDATA[<p>Wenn du dir die Mühe machst die Frage in 2 Foren zu stellen, beantworte ich sie dir auch in 2 Foren <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<p>Ich würde deine Funktionen umschreiben, im Moment macht sie eh nicht viel Sinn</p>
<pre><code class="language-cpp">float promilleRechner(float liter, float volumen, int gewicht){
  float alc = liter * volume;
  return (alc / gewicht * 1000L);
}
</code></pre>
<p>Deine bisherige Funktion vollbier() gibt immer nur die Promille für 2 Liter zurück.<br />
Da du die Werte in deiner Main ja zeilenweise mit konstanten Literwert macht, könnte das dann so aussehen.</p>
<pre><code class="language-cpp">int main (){
int Gewicht;
float volBier = 0.06, volSchnaps = 0.2;

/* Menü und so */

  for (int i = 1; i &lt; 11; i++){
     cout &lt;&lt; i * 0.2 &lt;&lt; &quot;  &quot; &lt;&lt; promilleRechner(i * 0.2, volBier, Gewicht) &lt;&lt; &quot;  &quot; &lt;&lt; promilleRechner(i * 0.2, volSchanps, Gewicht) &lt;&lt; endl;
  }

/* .......... */

}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/892638</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/892638</guid><dc:creator><![CDATA[imhotep]]></dc:creator><pubDate>Fri, 14 Oct 2005 20:49:15 GMT</pubDate></item><item><title><![CDATA[Reply to String aus Funktion on Fri, 14 Oct 2005 20:48:59 GMT]]></title><description><![CDATA[<p>danke, werde mir deine tipps mal zu gemüte führen.. das mit dem if (menu =='3') ist zum beenden, ich hab halt das return noch nicht geschrieben....</p>
<p>und wenn du eine bessere methode kennst, tabellen in der konsole darzustellen, währe ich über deinen vorschlag dankbar</p>
<p>mfg. Florian</p>
]]></description><link>https://www.c-plusplus.net/forum/post/892639</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/892639</guid><dc:creator><![CDATA[FlorianW]]></dc:creator><pubDate>Fri, 14 Oct 2005 20:48:59 GMT</pubDate></item><item><title><![CDATA[Reply to String aus Funktion on Fri, 14 Oct 2005 20:55:01 GMT]]></title><description><![CDATA[<p>FlorianW schrieb:</p>
<blockquote>
<pre><code class="language-cpp">if (menu =='2')

    {
        cout&lt;&lt;&quot;Menge   Bier        Wein      Wodka     Stroh-Rum&quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; (l)       Promille Promille  Promille  Promille &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot;----------------------------------------------------- &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 0.2       &quot;&lt;&lt;volbier()&lt;&lt;&quot;                                             &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 0.3                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 0.4                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 0.5                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 0.6                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 0.7                                                  &quot;&lt;&lt;endl;  
        cout&lt;&lt;&quot; 0.8                                                  &quot;&lt;&lt;endl;  
        cout&lt;&lt;&quot; 0.9                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 1.0                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 1.1                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 1.2                                                  &quot;&lt;&lt;endl;  
        cout&lt;&lt;&quot; 1.3                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 1.4                                                  &quot;&lt;&lt;endl;  
        cout&lt;&lt;&quot; 1.5                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 1.6                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 1.7                                                  &quot;&lt;&lt;endl;    
        cout&lt;&lt;&quot; 1.8                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 1.9                                                  &quot;&lt;&lt;endl;
        cout&lt;&lt;&quot; 2.0                                                  &quot;&lt;&lt;endl;  
    };
</code></pre>
</blockquote>
<p>Oh Gott! Mach das weg!</p>
<p>Bye, TGGC (<a href="http://tggc.tg.funpic.de/index.php?cat=4" rel="nofollow">Demo or Die</a>)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/892643</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/892643</guid><dc:creator><![CDATA[TGGC]]></dc:creator><pubDate>Fri, 14 Oct 2005 20:55:01 GMT</pubDate></item><item><title><![CDATA[Reply to String aus Funktion on Fri, 14 Oct 2005 21:07:06 GMT]]></title><description><![CDATA[<p>TGGC schrieb:</p>
<blockquote>
<p>Oh Gott! Mach das weg!</p>
</blockquote>
<p>jo, 'cout' ist dreck. ein schickes 'puts' hätt's auch getan</p>
]]></description><link>https://www.c-plusplus.net/forum/post/892651</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/892651</guid><dc:creator><![CDATA[net 0]]></dc:creator><pubDate>Fri, 14 Oct 2005 21:07:06 GMT</pubDate></item><item><title><![CDATA[Reply to String aus Funktion on Fri, 14 Oct 2005 21:18:50 GMT]]></title><description><![CDATA[<p>net schrieb:</p>
<blockquote>
<p>jo, 'cout' ist dreck. ein schickes 'puts' hätt's auch getan</p>
</blockquote>
<p>Aber puts ist doch C <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/892659</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/892659</guid><dc:creator><![CDATA[imhotep]]></dc:creator><pubDate>Fri, 14 Oct 2005 21:18:50 GMT</pubDate></item><item><title><![CDATA[Reply to String aus Funktion on Fri, 14 Oct 2005 21:21:54 GMT]]></title><description><![CDATA[<p>imhotep schrieb:</p>
<blockquote>
<p>net schrieb:</p>
<blockquote>
<p>jo, 'cout' ist dreck. ein schickes 'puts' hätt's auch getan</p>
</blockquote>
<p>Aber puts ist doch C <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /></p>
</blockquote>
<p>macht nichts. geht trotzdem. das ist ja das schöne an c++, die 99%ige c-kompatibilität</p>
]]></description><link>https://www.c-plusplus.net/forum/post/892663</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/892663</guid><dc:creator><![CDATA[net 0]]></dc:creator><pubDate>Fri, 14 Oct 2005 21:21:54 GMT</pubDate></item><item><title><![CDATA[Reply to String aus Funktion on Sat, 15 Oct 2005 07:40:57 GMT]]></title><description><![CDATA[<blockquote>
<pre><code class="language-cpp">for (int i = 1; i &lt; 11; i++){
     cout &lt;&lt; i * 0.2 &lt;&lt; &quot;  &quot; &lt;&lt; promilleRechner(i * 0.2, volBier, Gewicht) &lt;&lt; &quot;  &quot; &lt;&lt; promilleRechner(i * 0.2, volSchanps, Gewicht) &lt;&lt; endl;
  }
</code></pre>
</blockquote>
<p>Das gibt doch schon eine Art Tabelle aus, oder nich?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/892713</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/892713</guid><dc:creator><![CDATA[Panke]]></dc:creator><pubDate>Sat, 15 Oct 2005 07:40:57 GMT</pubDate></item><item><title><![CDATA[Reply to String aus Funktion on Sat, 15 Oct 2005 14:00:35 GMT]]></title><description><![CDATA[<p>Panke schrieb:</p>
<blockquote>
<p>Das gibt doch schon eine Art Tabelle aus, oder nich?</p>
</blockquote>
<p>Na das hoff ich doch <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /><br />
Muss man nur noch einen passenden Tabellenkopf für basteln, vielleicht noch eine Trennung der Spalten machen, ............ hier und da ein paar Blümchen und Bienchen, ........ sollte ja nur das Prinzip zeigen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/892849</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/892849</guid><dc:creator><![CDATA[imhotep]]></dc:creator><pubDate>Sat, 15 Oct 2005 14:00:35 GMT</pubDate></item></channel></rss>