<?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[Unklarer Ablauf in do while schleife]]></title><description><![CDATA[<p>Hallo ich habe ein Problem mit folgender Schleife:</p>
<pre><code class="language-cpp">do
  {
	  textcolor(30);
	  gotoxy(X+1,Y+2); cout &lt;&lt;&quot;                                           &quot;;
	  gotoxy(X+1,Y+3); cout &lt;&lt;&quot;                                           &quot;;
          gotoxy(X+1,Y+4); cout &lt;&lt;&quot;                                           &quot;;
          gotoxy(X+1,Y+5); cout &lt;&lt;&quot;                                           &quot;;
          gotoxy(X+1,Y+6); cout &lt;&lt;&quot;                                           &quot;;
          gotoxy(X+1,Y+7); cout &lt;&lt;&quot;                                           &quot;;
	  gotoxy(X+1,Y+3); cout &lt;&lt;&quot; Eingabe der Anzahl ...  &quot;;cin &gt;&gt; addgroups;
	  //addgroups = int(caddgroups);

	  if(addgroups &lt;1)
	  { 
		textcolor(28);
		gotoxy(X+1,Y+2); cout &lt;&lt;&quot; Mindestanzahl Gruppen =  eins  !!!                           &quot;;
		gotoxy(X+1,Y+3);
		Sleep(warte);
	  }
	  else if(addgroups + spiel.Gruppen &gt; 5)
	  {
		textcolor(28);
		gotoxy(X+1,Y+2); cout &lt;&lt;&quot; Gruppen Hoechstanzahl ueberschritten !!!  &quot;;
		gotoxy(X+1,Y+3);
		Sleep(warte);
	  }
  }
  while(addgroups + spiel.Gruppen &gt;5 || addgroups &lt;1 );
</code></pre>
<p>Immer wenn für cin &gt;&gt; addgroup anstatt einer Zahl ein char eingeben wird<br />
ensteht eine endlos- schleife mit eventuellem pc absturz,<br />
obwohl eigentlich der user je durchlauf addgroup aktuallisieren müsste.<br />
wird jedoch einfach ignoriert.<br />
wieso?? und wie kann man falsch eingaben absichern.<br />
dachte vielleicht die eingabe als char zur ermöglichen und diese variable dann in einen integer wert zu wandeln, jedoch hängt das programm dann trotzdem in einer<br />
endlos schleife fest.</p>
<p>wie gesagt dann wird mein cin einfach ignoriert???</p>
<p>kann mir da jemand helfen?</p>
<p>mfg Conroe</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/215095/unklarer-ablauf-in-do-while-schleife</link><generator>RSS for Node</generator><lastBuildDate>Mon, 12 Oct 2026 20:17:47 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/215095.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 06 Jun 2008 11:47:23 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Unklarer Ablauf in do while schleife on Fri, 06 Jun 2008 11:49:30 GMT]]></title><description><![CDATA[<p>Hallo ich habe ein Problem mit folgender Schleife:</p>
<pre><code class="language-cpp">do
  {
	  textcolor(30);
	  gotoxy(X+1,Y+2); cout &lt;&lt;&quot;                                           &quot;;
	  gotoxy(X+1,Y+3); cout &lt;&lt;&quot;                                           &quot;;
          gotoxy(X+1,Y+4); cout &lt;&lt;&quot;                                           &quot;;
          gotoxy(X+1,Y+5); cout &lt;&lt;&quot;                                           &quot;;
          gotoxy(X+1,Y+6); cout &lt;&lt;&quot;                                           &quot;;
          gotoxy(X+1,Y+7); cout &lt;&lt;&quot;                                           &quot;;
	  gotoxy(X+1,Y+3); cout &lt;&lt;&quot; Eingabe der Anzahl ...  &quot;;cin &gt;&gt; addgroups;
	  //addgroups = int(caddgroups);

	  if(addgroups &lt;1)
	  { 
		textcolor(28);
		gotoxy(X+1,Y+2); cout &lt;&lt;&quot; Mindestanzahl Gruppen =  eins  !!!                           &quot;;
		gotoxy(X+1,Y+3);
		Sleep(warte);
	  }
	  else if(addgroups + spiel.Gruppen &gt; 5)
	  {
		textcolor(28);
		gotoxy(X+1,Y+2); cout &lt;&lt;&quot; Gruppen Hoechstanzahl ueberschritten !!!  &quot;;
		gotoxy(X+1,Y+3);
		Sleep(warte);
	  }
  }
  while(addgroups + spiel.Gruppen &gt;5 || addgroups &lt;1 );
</code></pre>
<p>Immer wenn für cin &gt;&gt; addgroup anstatt einer Zahl ein char eingeben wird<br />
ensteht eine endlos- schleife mit eventuellem pc absturz,<br />
obwohl eigentlich der user je durchlauf addgroup aktuallisieren müsste.<br />
wird jedoch einfach ignoriert.<br />
wieso?? und wie kann man falsch eingaben absichern.<br />
dachte vielleicht die eingabe als char zur ermöglichen und diese variable dann in einen integer wert zu wandeln, jedoch hängt das programm dann trotzdem in einer<br />
endlos schleife fest.</p>
<p>wie gesagt dann wird mein cin einfach ignoriert???</p>
<p>kann mir da jemand helfen?</p>
<p>mfg Conroe</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1524005</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1524005</guid><dc:creator><![CDATA[conroe]]></dc:creator><pubDate>Fri, 06 Jun 2008 11:49:30 GMT</pubDate></item><item><title><![CDATA[Reply to Unklarer Ablauf in do while schleife on Fri, 06 Jun 2008 12:51:19 GMT]]></title><description><![CDATA[<p>Vorschlag: Gebe einen String statt einen Integer ein und werte diesen selbst aus, dann hast du alles in der Hand.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1524056</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1524056</guid><dc:creator><![CDATA[berniebutt]]></dc:creator><pubDate>Fri, 06 Jun 2008 12:51:19 GMT</pubDate></item><item><title><![CDATA[Reply to Unklarer Ablauf in do while schleife on Fri, 06 Jun 2008 12:55:37 GMT]]></title><description><![CDATA[<p>Wir vereinfachen das Problem:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

int main()
{
	int i;
	do
	{
		std::cin &gt;&gt; i;

	}while( i != 0 );
	return 0;
}
</code></pre>
<p>Das reicht erstmal um den Fehler zu erzeugen.<br />
Sobald eine Eingabe auftaucht, die cin nicht verarbeiten kann setzt er das Fehlerflag und gibt keine Werte mehr her.<br />
Fehler kann man mit operator! abfragen.<br />
z.B.:</p>
<pre><code class="language-cpp">int main()
{
	int i;
	do
	{
		std::cin &gt;&gt; i;
		if( !std::cin ) break; // oder wie man eben reagieren möchte...

	}while( i != 0 );
	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1524060</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1524060</guid><dc:creator><![CDATA[wandrer]]></dc:creator><pubDate>Fri, 06 Jun 2008 12:55:37 GMT</pubDate></item><item><title><![CDATA[Reply to Unklarer Ablauf in do while schleife on Fri, 06 Jun 2008 14:18:40 GMT]]></title><description><![CDATA[<p>Ok danke erstmal,</p>
<p>bin deinem ratschlag gefolgt, funktioniert auch soweit.<br />
aber wie kann ich dem cin objekt wieder klarmachen das es wieder<br />
werte entgegen nehmen soll?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1524117</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1524117</guid><dc:creator><![CDATA[conroe]]></dc:creator><pubDate>Fri, 06 Jun 2008 14:18:40 GMT</pubDate></item><item><title><![CDATA[Reply to Unklarer Ablauf in do while schleife on Fri, 06 Jun 2008 23:20:39 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">std::cin.clear(); // Löscht alle Fehlerflags.
std::cin.sync(); // Überspringt alle bisher gelesenen Zeichen.
</code></pre>
<p>Grüssli</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1524461</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1524461</guid><dc:creator><![CDATA[Dravere]]></dc:creator><pubDate>Fri, 06 Jun 2008 23:20:39 GMT</pubDate></item><item><title><![CDATA[Reply to Unklarer Ablauf in do while schleife on Sat, 07 Jun 2008 09:20:01 GMT]]></title><description><![CDATA[<p>Puffer leeren ist auch angebracht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1524543</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1524543</guid><dc:creator><![CDATA[polkappe]]></dc:creator><pubDate>Sat, 07 Jun 2008 09:20:01 GMT</pubDate></item><item><title><![CDATA[Reply to Unklarer Ablauf in do while schleife on Sat, 07 Jun 2008 18:05:40 GMT]]></title><description><![CDATA[<p>aber die methode clear() ist bestimmt sehr hilfreich gleich mal ausprobieren.<br />
thx <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>
<p>std::cin.sync(); // Überspringt alle bisher gelesenen Zeichen.<br />
Was meinst du damit genau?</p>
<p>Und wie leere ich den Puffer? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1524767</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1524767</guid><dc:creator><![CDATA[conroe]]></dc:creator><pubDate>Sat, 07 Jun 2008 18:05:40 GMT</pubDate></item><item><title><![CDATA[Reply to Unklarer Ablauf in do while schleife on Sat, 07 Jun 2008 19:24:22 GMT]]></title><description><![CDATA[<p>flush()</p>
<p>glaub ich...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1524805</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1524805</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Sat, 07 Jun 2008 19:24:22 GMT</pubDate></item></channel></rss>