<?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 do - while Loop]]></title><description><![CDATA[<p>Hallo Zusammen</p>
<p>bin ganz neu hier und habe erst vor ein paar Tagen mich mit C++ beschäftigt und &quot;gelernt&quot;...<br />
Um ein bisschen rein zu kommen habe ich ein Quiz erstellt, das ganze funktioniert auch soweit ! nur ein kleines Problem habe ich....</p>
<p>Ich habe 3 Fragen erstellt, sollte man die falsche Antwort geben, kann man durch 'y' nochmal versuchen, allerdings die selbe Frage, wie kann ich den do-while Loop einstellen, das man wieder ganz von vorne anfängt? - bei Frage 1 ?</p>
<p>Freu mich auf eure Vorschläge bzw. auf allg. Verbesserungen am Code, da ich glaube noch recht umständlich geschrieben habe als blutfrischer Anfänger <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>
<pre><code>#include &lt;iostream&gt;
#include &lt;string&gt;

using namespace std;

int main ()
{
    string por (&quot;lissabon&quot;), spa (&quot;madrid&quot;), fra (&quot;paris&quot;);
    string por1, spa1, fra1;
    char neu = 'y';

    do
    {
         cout &lt;&lt; &quot;Wie heisst die Hauptstadt von Portugal ? \n&quot; &lt;&lt; endl;
         cin &gt;&gt; por1;

         if (por == por1)
         {
         cout &lt;&lt; &quot;BRAVO !&quot; &lt;&lt; endl;
         getchar();

   do
   {
         cout &lt;&lt; &quot;Wie heisst die Hauptstadt von Spanien ? \n&quot; &lt;&lt; endl;
         cin &gt;&gt; spa1;

         if (spa == spa1)
         {
                 cout &lt;&lt; &quot;BRAVO !&quot; &lt;&lt; endl;
                 getchar();

do
{
                 cout &lt;&lt; &quot;Wie heisst die Hauptstadt von Frankreich ? \n&quot; &lt;&lt; endl;
                 cin &gt;&gt; fra1;

                 if (fra == fra1)
                 {
                         cout &lt;&lt; &quot;BRAVO !&quot; &lt;&lt; endl;
                         getchar();

                         }
                 else
                 cout &lt;&lt; &quot;Das war leider falsch! Moechten Sie neu starten (y/n) ? \n)&quot; &lt;&lt; endl;
                 cin &gt;&gt; neu; 
                 }
                 while (neu !='n');
         }        
         else
         cout &lt;&lt; &quot;Das war leider falsch! Moechten Sie neu starten (y/n) ? \n)&quot; &lt;&lt; endl;
         cin &gt;&gt; neu;      
         } 
          while (neu !='n');

         }

         else
         cout &lt;&lt; &quot;Das war leider falsch! Moechten Sie neu starten (y/n) ? \n)&quot; &lt;&lt; endl;
         cin &gt;&gt; neu;      

             }

   while (neu !='n');

    }
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/313019/frage-zu-do-while-loop</link><generator>RSS for Node</generator><lastBuildDate>Sun, 02 Aug 2026 08:35:54 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/313019.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 19 Jan 2013 20:46:55 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Frage zu do - while Loop on Sat, 19 Jan 2013 20:46:55 GMT]]></title><description><![CDATA[<p>Hallo Zusammen</p>
<p>bin ganz neu hier und habe erst vor ein paar Tagen mich mit C++ beschäftigt und &quot;gelernt&quot;...<br />
Um ein bisschen rein zu kommen habe ich ein Quiz erstellt, das ganze funktioniert auch soweit ! nur ein kleines Problem habe ich....</p>
<p>Ich habe 3 Fragen erstellt, sollte man die falsche Antwort geben, kann man durch 'y' nochmal versuchen, allerdings die selbe Frage, wie kann ich den do-while Loop einstellen, das man wieder ganz von vorne anfängt? - bei Frage 1 ?</p>
<p>Freu mich auf eure Vorschläge bzw. auf allg. Verbesserungen am Code, da ich glaube noch recht umständlich geschrieben habe als blutfrischer Anfänger <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>
<pre><code>#include &lt;iostream&gt;
#include &lt;string&gt;

using namespace std;

int main ()
{
    string por (&quot;lissabon&quot;), spa (&quot;madrid&quot;), fra (&quot;paris&quot;);
    string por1, spa1, fra1;
    char neu = 'y';

    do
    {
         cout &lt;&lt; &quot;Wie heisst die Hauptstadt von Portugal ? \n&quot; &lt;&lt; endl;
         cin &gt;&gt; por1;

         if (por == por1)
         {
         cout &lt;&lt; &quot;BRAVO !&quot; &lt;&lt; endl;
         getchar();

   do
   {
         cout &lt;&lt; &quot;Wie heisst die Hauptstadt von Spanien ? \n&quot; &lt;&lt; endl;
         cin &gt;&gt; spa1;

         if (spa == spa1)
         {
                 cout &lt;&lt; &quot;BRAVO !&quot; &lt;&lt; endl;
                 getchar();

do
{
                 cout &lt;&lt; &quot;Wie heisst die Hauptstadt von Frankreich ? \n&quot; &lt;&lt; endl;
                 cin &gt;&gt; fra1;

                 if (fra == fra1)
                 {
                         cout &lt;&lt; &quot;BRAVO !&quot; &lt;&lt; endl;
                         getchar();

                         }
                 else
                 cout &lt;&lt; &quot;Das war leider falsch! Moechten Sie neu starten (y/n) ? \n)&quot; &lt;&lt; endl;
                 cin &gt;&gt; neu; 
                 }
                 while (neu !='n');
         }        
         else
         cout &lt;&lt; &quot;Das war leider falsch! Moechten Sie neu starten (y/n) ? \n)&quot; &lt;&lt; endl;
         cin &gt;&gt; neu;      
         } 
          while (neu !='n');

         }

         else
         cout &lt;&lt; &quot;Das war leider falsch! Moechten Sie neu starten (y/n) ? \n)&quot; &lt;&lt; endl;
         cin &gt;&gt; neu;      

             }

   while (neu !='n');

    }
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2291439</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2291439</guid><dc:creator><![CDATA[Giallorosso]]></dc:creator><pubDate>Sat, 19 Jan 2013 20:46:55 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu do - while Loop on Sat, 19 Jan 2013 21:24:18 GMT]]></title><description><![CDATA[<p>Willkommen im Forum!<br />
Ich verstehe nicht ganz: soll er nur die falsch beantwortete Frage wiederholen oder den ganzen Quiz erneut starten?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2291446</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2291446</guid><dc:creator><![CDATA[*Rewind*]]></dc:creator><pubDate>Sat, 19 Jan 2013 21:24:18 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu do - while Loop on Sat, 19 Jan 2013 21:30:43 GMT]]></title><description><![CDATA[<p>stand jetzt, wiederholt er die falsch beantwortete Frage...</p>
<p>Ich möchte allerdigns das er wieder bei Frage 1 anfängt <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 />
habe auch schon bissle im netz gesucht aber leider nichts gefunden was passen könnte</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2291447</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2291447</guid><dc:creator><![CDATA[Giallorosso]]></dc:creator><pubDate>Sat, 19 Jan 2013 21:30:43 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu do - while Loop on Sat, 19 Jan 2013 21:54:34 GMT]]></title><description><![CDATA[<p>Pseudocode als Ansatz:</p>
<pre><code>while(true)
{
    frage1 stellen
    Ergebnis ausgeben (richtig/falsch)
    cin.ignore(cin.rdbuf()-&gt;in_avail()); //leere alle Zeichen im Puffer
    if (getchar() == 'y')
        continue;

    frage2 stellen
    Ergebnis ausgeben
    cin.ignore(cin.rdbuf()-&gt;in_avail());
    if (getchar() == 'y')
        continue;

    ...

    letzte_frage_stellen()
    if (eingabe == richtigeAntwort)
    {
        cout &lt;&lt; &quot;Sie haben gewonnen!\n&quot;;
        break;
    }
}
</code></pre>
<p>Der Vorschlag ist aber auf dein Konzept zugeschnitten und müsste komplett umgebaut werden, wenn die Fragen z.B. in einer Schleife und nicht jede einzeln gestellt werden.</p>
<p>Edit: ein paar Tipps meinerseits:<br />
- using namespace std; nicht global deklarieren<br />
- zum Speichern der Eingabe kannst du auch dieselbe Variable verwenden (wird jedes Mal überschrieben)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2291448</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2291448</guid><dc:creator><![CDATA[*Rewind*]]></dc:creator><pubDate>Sat, 19 Jan 2013 21:54:34 GMT</pubDate></item></channel></rss>