<?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[Mehrmalige Eingabe mit while]]></title><description><![CDATA[<p>Hallo Freunde von Bit und Byte,</p>
<p>ich muss folgende Aufgabe lösen:<br />
<em>Schreibe ein Programm, das immer wieder die Eingabe eines Wortes mit 5<br />
Buchstaben fordert und erst Ruhe gibt, wenn es eine Eingabe aus 5 Zeichen<br />
bekommen hat.</em></p>
<p>Folgendes habe ich probiert:</p>
<pre><code>#include &lt;iostream&gt;
using namespace std;

bool eingabe_wort_5(char wort[]){
int zaehler = 0;
	for (int i = 0; wort[i] != '\0'; i++){
		zaehler += 1;
	}
	if (zaehler != 5){
		cout &lt;&lt; &quot;Das Wort &quot; &lt;&lt; wort &lt;&lt; &quot; besteht aus &quot; &lt;&lt; zaehler &lt;&lt;
			 &quot; Buchstaben. Nochmal.&quot; &lt;&lt; endl;
		return true;	
	}
	else{
		cout &lt;&lt; &quot;Das Wort hat &quot; &lt;&lt; zaehler &lt;&lt; 
			&quot; Buchstaben. Das Programm wird beendet.&quot; &lt;&lt; endl;
		return false;
	}
}

int main(int argc, char** argv) {
	char wort[100];
do{
	cout &lt;&lt; &quot;Wort eingeben: &quot;;
	cin &gt;&gt; wort;
	eingabe_wort_5(wort);
}while(true);

	return 0;
}
</code></pre>
<p>Problem ist:</p>
<p>Wenn ich genau 5 Buchstaben eingebe, bricht die Schleife nicht ab.</p>
<p>Was habe ich falsch gemacht ?</p>
<p>Ich bedanke mich im Voraus.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/333010/mehrmalige-eingabe-mit-while</link><generator>RSS for Node</generator><lastBuildDate>Mon, 27 Apr 2026 07:57:08 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/333010.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 05 Jun 2015 17:21:15 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Mehrmalige Eingabe mit while on Fri, 05 Jun 2015 17:21:15 GMT]]></title><description><![CDATA[<p>Hallo Freunde von Bit und Byte,</p>
<p>ich muss folgende Aufgabe lösen:<br />
<em>Schreibe ein Programm, das immer wieder die Eingabe eines Wortes mit 5<br />
Buchstaben fordert und erst Ruhe gibt, wenn es eine Eingabe aus 5 Zeichen<br />
bekommen hat.</em></p>
<p>Folgendes habe ich probiert:</p>
<pre><code>#include &lt;iostream&gt;
using namespace std;

bool eingabe_wort_5(char wort[]){
int zaehler = 0;
	for (int i = 0; wort[i] != '\0'; i++){
		zaehler += 1;
	}
	if (zaehler != 5){
		cout &lt;&lt; &quot;Das Wort &quot; &lt;&lt; wort &lt;&lt; &quot; besteht aus &quot; &lt;&lt; zaehler &lt;&lt;
			 &quot; Buchstaben. Nochmal.&quot; &lt;&lt; endl;
		return true;	
	}
	else{
		cout &lt;&lt; &quot;Das Wort hat &quot; &lt;&lt; zaehler &lt;&lt; 
			&quot; Buchstaben. Das Programm wird beendet.&quot; &lt;&lt; endl;
		return false;
	}
}

int main(int argc, char** argv) {
	char wort[100];
do{
	cout &lt;&lt; &quot;Wort eingeben: &quot;;
	cin &gt;&gt; wort;
	eingabe_wort_5(wort);
}while(true);

	return 0;
}
</code></pre>
<p>Problem ist:</p>
<p>Wenn ich genau 5 Buchstaben eingebe, bricht die Schleife nicht ab.</p>
<p>Was habe ich falsch gemacht ?</p>
<p>Ich bedanke mich im Voraus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2455873</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2455873</guid><dc:creator><![CDATA[Denkfehler]]></dc:creator><pubDate>Fri, 05 Jun 2015 17:21:15 GMT</pubDate></item><item><title><![CDATA[Reply to Mehrmalige Eingabe mit while on Fri, 05 Jun 2015 17:23:28 GMT]]></title><description><![CDATA[<p>Zeile 27.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2455874</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2455874</guid><dc:creator><![CDATA[SG1]]></dc:creator><pubDate>Fri, 05 Jun 2015 17:23:28 GMT</pubDate></item><item><title><![CDATA[Reply to Mehrmalige Eingabe mit while on Fri, 05 Jun 2015 17:32:32 GMT]]></title><description><![CDATA[<p>SG1 schrieb:</p>
<blockquote>
<p>Zeile 27.</p>
</blockquote>
<p>Ging ja schnell.<br />
Jetzt weiß ich wo der Fehler liegt, aber komme nicht drauf was genau falsch ist.</p>
<p>Es sollte solange wiederholt werden, solange die Bedingung true ( Eingabe ungleich 5) erfüllt ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2455875</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2455875</guid><dc:creator><![CDATA[Denkfehler]]></dc:creator><pubDate>Fri, 05 Jun 2015 17:32:32 GMT</pubDate></item><item><title><![CDATA[Reply to Mehrmalige Eingabe mit while on Fri, 05 Jun 2015 17:50:10 GMT]]></title><description><![CDATA[<p>Denkfehler schrieb:</p>
<blockquote>
<p>Es sollte solange wiederholt werden, solange die Bedingung true ( Eingabe ungleich 5) erfüllt ist.</p>
</blockquote>
<p>Die Bedingung kommt zwischen die Klammern. <code>while(true)</code> hat quasi gar keine Bedingung - die Schleife wird solange wiederholt bis sie anderweitig abgebrochen wird (e.g. durch <code>break</code> ).</p>
<p>Kleiner Tipp, falls du Clang oder GCC verwendest: Siehst du eine Warnung wenn du die Definition zu</p>
<pre><code>&lsqb;&lsqb;gnu::warn_unused_result&rsqb;&rsqb;  bool eingabe_wort_5(char wort[]){
int zaehler = 0;
    for (int i = 0; wort[i] != '\0'; i++){
        zaehler += 1;
    }
    if (zaehler != 5){
        cout &lt;&lt; &quot;Das Wort &quot; &lt;&lt; wort &lt;&lt; &quot; besteht aus &quot; &lt;&lt; zaehler &lt;&lt;
             &quot; Buchstaben. Nochmal.&quot; &lt;&lt; endl;
        return true;    
    }
    else{
        cout &lt;&lt; &quot;Das Wort hat &quot; &lt;&lt; zaehler &lt;&lt; 
            &quot; Buchstaben. Das Programm wird beendet.&quot; &lt;&lt; endl;
        return false;
    }
}
</code></pre>
<p>abänderst? Bei VC++ kommt statt dem <code>&lsqb;&lsqb;..&rsqb;&rsqb;</code> -Attribut ein <code>_Check_return_</code> hin.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2455876</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2455876</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Fri, 05 Jun 2015 17:50:10 GMT</pubDate></item><item><title><![CDATA[Reply to Mehrmalige Eingabe mit while on Fri, 05 Jun 2015 17:47:26 GMT]]></title><description><![CDATA[<p>Deine Schleife läuft halt so lange, wie true true ist... also für immer. Trag 'ne andere Bedingung ein, und die Schleife bricht vielleicht auch ab.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2455878</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2455878</guid><dc:creator><![CDATA[SG1]]></dc:creator><pubDate>Fri, 05 Jun 2015 17:47:26 GMT</pubDate></item><item><title><![CDATA[Reply to Mehrmalige Eingabe mit while on Fri, 05 Jun 2015 20:39:32 GMT]]></title><description><![CDATA[<p>Hmmm, hört sich alles so plausibel an, wenn man das von den anderen hört ( bzw. liest)... Vielen dank an der Stelle.</p>
<p>Arcoth schrieb:</p>
<blockquote>
<p>Die Bedingung kommt zwischen die Klammern. <code>while(true)</code> hat quasi gar keine Bedingung - die Schleife wird solange wiederholt bis sie anderweitig abgebrochen wird (e.g. durch <code>break</code> ).</p>
</blockquote>
<p>SG1 schrieb:</p>
<blockquote>
<p>Deine Schleife läuft halt so lange, wie true true ist... also für immer. Trag 'ne andere Bedingung ein, und die Schleife bricht vielleicht auch ab.</p>
</blockquote>
<p>Hört sich logisch an.</p>
<p>Arcoth schrieb:</p>
<blockquote>
<p>Kleiner Tipp, falls du Clang oder GCC verwendest: Siehst du eine Warnung wenn du die Definition zu</p>
<pre><code>&lsqb;&lsqb;gnu::warn_unused_result&rsqb;&rsqb; ...
</code></pre>
<p>abänderst? Bei VC++ kommt statt dem &lsqb;&lsqb;..&rsqb;&rsqb;-Attribut ein _Check_return_ hin.</p>
</blockquote>
<p>Jawohl, der Compiler beschwert sich:</p>
<pre><code>[Error] expected unqualified-id before '[' token
</code></pre>
<p>Habe den Code folgendermaßen geändert:</p>
<pre><code>#include &lt;iostream&gt;
using namespace std;

/*&lsqb;&lsqb;gnu::warn_unused_result&rsqb;&rsqb;*/ int eingabe_wort_5(char wort[]){
	int zaehler = 0;
	for (int i = 0; wort[i] != '\0'; i++){
		zaehler += 1;
	}

	return zaehler;
}

int main(int argc, char** argv) {
	char wort[100];
	int zaehler;

do{
	cout &lt;&lt; &quot;Wort eingeben: &quot;;
	cin &gt;&gt; wort;
	eingabe_wort_5(wort);
	if (eingabe_wort_5(wort) != 5){
		cout &lt;&lt; &quot;Das Wort &quot; &lt;&lt; wort &lt;&lt; &quot; besteht aus &quot; &lt;&lt; eingabe_wort_5(wort) &lt;&lt;
			 &quot; Buchstaben. Nochmal.&quot; &lt;&lt; endl;	
	}
	else{
		cout &lt;&lt; &quot;Das Wort hat &quot; &lt;&lt; eingabe_wort_5(wort) &lt;&lt; 
			&quot; Buchstaben. Das Programm wird beendet.&quot; &lt;&lt; endl;
	}
}while( eingabe_wort_5(wort) != 5);

return 0;
}
</code></pre>
<p>Nicht gerade die elegenteste Lösung, aber das funktioniert schonmal.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2455894</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2455894</guid><dc:creator><![CDATA[Denkfehler]]></dc:creator><pubDate>Fri, 05 Jun 2015 20:39:32 GMT</pubDate></item><item><title><![CDATA[Reply to Mehrmalige Eingabe mit while on Fri, 05 Jun 2015 21:05:35 GMT]]></title><description><![CDATA[<p>Hast du <code>-std=c++11</code> angegeben? Welche GCC Version verwendest du? Attribute dieser Art gibt es <a href="https://gcc.gnu.org/projects/cxx0x.html" rel="nofollow">seit GCC 4.8</a>.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2455899</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2455899</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Fri, 05 Jun 2015 21:05:35 GMT</pubDate></item><item><title><![CDATA[Reply to Mehrmalige Eingabe mit while on Fri, 05 Jun 2015 21:36:21 GMT]]></title><description><![CDATA[<p>Arcoth schrieb:</p>
<blockquote>
<p>Hast du <code>-std=c++11</code> angegeben? Welche GCC Version verwendest du? Attribute dieser Art gibt es <a href="https://gcc.gnu.org/projects/cxx0x.html" rel="nofollow">seit GCC 4.8</a>.</p>
</blockquote>
<p>In <code>CodeBlocks</code> ( mit TDM-GCC compiler, version 4.8.1) ist das Häkchen bei <code>-std = c++11</code> da.</p>
<p><code>Visual Studio 2013</code> mit</p>
<pre><code>_Check_return_
</code></pre>
<p>meckert nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2455906</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2455906</guid><dc:creator><![CDATA[Denkfehler]]></dc:creator><pubDate>Fri, 05 Jun 2015 21:36:21 GMT</pubDate></item><item><title><![CDATA[Reply to Mehrmalige Eingabe mit while on Fri, 05 Jun 2015 21:50:33 GMT]]></title><description><![CDATA[<p>Denkfehler schrieb:</p>
<blockquote>
<p>Arcoth schrieb:</p>
<blockquote>
<p>Hast du <code>-std=c++11</code> angegeben? Welche GCC Version verwendest du? Attribute dieser Art gibt es <a href="https://gcc.gnu.org/projects/cxx0x.html" rel="nofollow">seit GCC 4.8</a>.</p>
</blockquote>
<p>In <code>CodeBlocks</code> ( mit TDM-GCC compiler, version 4.8.1) ist das Häkchen bei <code>-std = c++11</code> da.</p>
</blockquote>
<p><a href="http://melpon.org/wandbox/permlink/9eSusPEud5NvXr7g" rel="nofollow">Merkwürdig</a>.</p>
<p>Kompiliert der Code im Link auch nicht, der minimale?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2455908</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2455908</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Fri, 05 Jun 2015 21:50:33 GMT</pubDate></item><item><title><![CDATA[Reply to Mehrmalige Eingabe mit while on Sat, 06 Jun 2015 19:16:22 GMT]]></title><description><![CDATA[<p>Arcoth schrieb:</p>
<blockquote>
<p>Denkfehler schrieb:</p>
<blockquote>
<p>Arcoth schrieb:</p>
<blockquote>
<p>Hast du <code>-std=c++11</code> angegeben? Welche GCC Version verwendest du? Attribute dieser Art gibt es <a href="https://gcc.gnu.org/projects/cxx0x.html" rel="nofollow">seit GCC 4.8</a>.</p>
</blockquote>
<p>In <code>CodeBlocks</code> ( mit TDM-GCC compiler, version 4.8.1) ist das Häkchen bei <code>-std = c++11</code> da.</p>
</blockquote>
<p><a href="http://melpon.org/wandbox/permlink/9eSusPEud5NvXr7g" rel="nofollow">Merkwürdig</a>.</p>
<p>Kompiliert der Code im Link auch nicht, der minimale?</p>
</blockquote>
<p>Nope. Compiler gibt folgende Fehlermeldung aus:</p>
<pre><code>||=== Build: Debug in Test_Forum_GCC (compiler: GNU GCC Compiler) ===|
...\main.cpp|4|error: expected unqualified-id before '[' token|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2455964</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2455964</guid><dc:creator><![CDATA[Denkfehler]]></dc:creator><pubDate>Sat, 06 Jun 2015 19:16:22 GMT</pubDate></item></channel></rss>