<?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[[gelöst]Abfrage auf Buchstaben ?!]]></title><description><![CDATA[<p>Hallo Leute,</p>
<p>folgendes Problem...<br />
Ich hab ein 10x10 gefülltes Array von A0 - A9 &amp; J0 - J9<br />
Wenn ich den Benutzer auffordere eine Koordinate einzutippen und er was richtig eintippt, funktioniert alles,<br />
doch wenn er nur &quot;asdfghjk&quot; oder nur &quot;a&quot; eintippt stürzt das Programm ab...</p>
<p>Das Problem Kind</p>
<pre><code>bool Mensch::angriff(Spielfeld* gegFeld)
{
	int zeile, spalte;
	string input;
	bool getroffen = false;
	bool gewonnen= false; 

	do 
	{

	cout &lt;&lt; &quot;Sie sind dran!&quot; &lt;&lt; endl;
	// koordinaten eingabe (zeile, spalte)
	getkoord(&quot;Waehlen Sie eine Koordinate&quot;, &amp;zeile, &amp;spalte);
	system(&quot;cls&quot;);
	// prüfe ob getroffen
	getroffen = gegFeld-&gt;getroffen(zeile, spalte);
	gegFeld-&gt;draw();

	if (getroffen)
	{
		if(gegFeld-&gt;gewonnen())
		{
			cout&lt;&lt; &quot;Sie haben gewonnen!&quot;&lt;&lt; endl;
			gewonnen= true;
		}
		else
		{
		cout &lt;&lt;&quot;Sie duerfen nochmal&quot;&lt;&lt; endl;
		}
	}
	else
	{
		cout &lt;&lt;&quot;Sie haben nichts getroffen&quot;&lt;&lt; endl;
		cout &lt;&lt;&quot;Der Computer ist jetzt dran&quot; &lt;&lt;endl;
	}
	}while(getroffen &amp;&amp; !gewonnen);

	return gewonnen;
}
</code></pre>
<p>Und dazu gehört</p>
<pre><code>void Mensch::getkoord(string text, int* zeile, int* spalte)
{
	string input;
	cout &lt;&lt; text &lt;&lt; endl;
	cin &gt;&gt; input;
	*zeile = getzeile(input);
	*spalte = getspalte(input);
}
//_________________________________________________________________________________________________

char Mensch::getrichtung()
{
	string input;
	cout &lt;&lt;&quot;rechts, links, oben, unten&quot;&lt;&lt;endl;
	cin &gt;&gt; input;
	return input[0];
}
//_________________________________________________________________________________________________

int Mensch::getzeile(string input)
{
	if(input[0]&lt;'a')
	{
	return input[0] - 'A';
	}
	else
	{
		return input[0] - 'a';
	}
}
</code></pre>
<p>Wo muss ich das jetzt mit der &quot;If Abfrage&quot; einfügen? Und gibt es sowas wie &quot;Wenn das eingegebende nicht mit dem feld inhalt übereinstimmt&quot;</p>
<p>- Nicht wundern über den Inhalt, ist alles noch in der Testphase <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61b.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_tongue"
      title=":P"
      alt="😛"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/topic/313591/gelöst-abfrage-auf-buchstaben</link><generator>RSS for Node</generator><lastBuildDate>Sun, 02 Aug 2026 03:55:01 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/313591.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 05 Feb 2013 08:32:38 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [gelöst]Abfrage auf Buchstaben ?! on Tue, 26 Nov 2013 13:04:37 GMT]]></title><description><![CDATA[<p>Hallo Leute,</p>
<p>folgendes Problem...<br />
Ich hab ein 10x10 gefülltes Array von A0 - A9 &amp; J0 - J9<br />
Wenn ich den Benutzer auffordere eine Koordinate einzutippen und er was richtig eintippt, funktioniert alles,<br />
doch wenn er nur &quot;asdfghjk&quot; oder nur &quot;a&quot; eintippt stürzt das Programm ab...</p>
<p>Das Problem Kind</p>
<pre><code>bool Mensch::angriff(Spielfeld* gegFeld)
{
	int zeile, spalte;
	string input;
	bool getroffen = false;
	bool gewonnen= false; 

	do 
	{

	cout &lt;&lt; &quot;Sie sind dran!&quot; &lt;&lt; endl;
	// koordinaten eingabe (zeile, spalte)
	getkoord(&quot;Waehlen Sie eine Koordinate&quot;, &amp;zeile, &amp;spalte);
	system(&quot;cls&quot;);
	// prüfe ob getroffen
	getroffen = gegFeld-&gt;getroffen(zeile, spalte);
	gegFeld-&gt;draw();

	if (getroffen)
	{
		if(gegFeld-&gt;gewonnen())
		{
			cout&lt;&lt; &quot;Sie haben gewonnen!&quot;&lt;&lt; endl;
			gewonnen= true;
		}
		else
		{
		cout &lt;&lt;&quot;Sie duerfen nochmal&quot;&lt;&lt; endl;
		}
	}
	else
	{
		cout &lt;&lt;&quot;Sie haben nichts getroffen&quot;&lt;&lt; endl;
		cout &lt;&lt;&quot;Der Computer ist jetzt dran&quot; &lt;&lt;endl;
	}
	}while(getroffen &amp;&amp; !gewonnen);

	return gewonnen;
}
</code></pre>
<p>Und dazu gehört</p>
<pre><code>void Mensch::getkoord(string text, int* zeile, int* spalte)
{
	string input;
	cout &lt;&lt; text &lt;&lt; endl;
	cin &gt;&gt; input;
	*zeile = getzeile(input);
	*spalte = getspalte(input);
}
//_________________________________________________________________________________________________

char Mensch::getrichtung()
{
	string input;
	cout &lt;&lt;&quot;rechts, links, oben, unten&quot;&lt;&lt;endl;
	cin &gt;&gt; input;
	return input[0];
}
//_________________________________________________________________________________________________

int Mensch::getzeile(string input)
{
	if(input[0]&lt;'a')
	{
	return input[0] - 'A';
	}
	else
	{
		return input[0] - 'a';
	}
}
</code></pre>
<p>Wo muss ich das jetzt mit der &quot;If Abfrage&quot; einfügen? Und gibt es sowas wie &quot;Wenn das eingegebende nicht mit dem feld inhalt übereinstimmt&quot;</p>
<p>- Nicht wundern über den Inhalt, ist alles noch in der Testphase <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61b.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_tongue"
      title=":P"
      alt="😛"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2296112</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2296112</guid><dc:creator><![CDATA[meinhana]]></dc:creator><pubDate>Tue, 26 Nov 2013 13:04:37 GMT</pubDate></item><item><title><![CDATA[Reply to [gelöst]Abfrage auf Buchstaben ?! on Tue, 05 Feb 2013 17:00:19 GMT]]></title><description><![CDATA[<p>Dieser Thread wurde von Moderator/in <a href="http://www.c-plusplus.net/forum/u18363" rel="nofollow">Jochen Kalmbach</a> aus dem Forum <a href="http://www.c-plusplus.net/forum/f58" rel="nofollow">C++/CLI mit .NET</a> in das Forum <a href="http://www.c-plusplus.net/forum/f15" rel="nofollow">C++ (auch C++0x und C++11)</a> verschoben.</p>
<p>Im Zweifelsfall bitte auch folgende Hinweise beachten:<br />
<a href="http://www.c-plusplus.net/forum/39405" rel="nofollow">C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?</a></p>
<p><em>Dieses Posting wurde automatisch erzeugt.</em></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2296265</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2296265</guid><dc:creator><![CDATA[C++ Forumbot]]></dc:creator><pubDate>Tue, 05 Feb 2013 17:00:19 GMT</pubDate></item><item><title><![CDATA[Reply to [gelöst]Abfrage auf Buchstaben ?! on Tue, 05 Feb 2013 19:46:21 GMT]]></title><description><![CDATA[<p>Scheinbar weiss niemand, was jetzt das konkrete Problem ist.</p>
<p>meinhana schrieb:</p>
<blockquote>
<p>Ich hab ein 10x10 gefülltes Array von A0 - A9 &amp; J0 - J9</p>
</blockquote>
<p>Dein Feld sieht so aus?</p>
<pre><code>A0 A1 A2...A9
J0
J1
J2
 .
 .
 .
J9
</code></pre>
<p>Was genau willst Du hier machen? Bzw.: wie sieht ein richtiger input fuer diese Funktion aus?<br />
z.B. &quot;A0&quot; oder &quot;a7&quot;, aber nicht &quot;asdf&quot; oder &quot;a&quot;?</p>
<pre><code class="language-cpp">int Mensch::getzeile(string input)
{
    if(input[0]&lt;'a')
    {
    return input[0] - 'A';
    }
    else
    {
        return input[0] - 'a';
    }
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2296288</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2296288</guid><dc:creator><![CDATA[Furble Wurble]]></dc:creator><pubDate>Tue, 05 Feb 2013 19:46:21 GMT</pubDate></item><item><title><![CDATA[Reply to [gelöst]Abfrage auf Buchstaben ?! on Wed, 06 Feb 2013 12:29:42 GMT]]></title><description><![CDATA[<p>Sofern du die Nerven dazu hast, schau dir mal &lt;<a href="http://de.cppreference.com/w/cpp/regex" rel="nofollow">regex</a>&gt; an.</p>
<p>Beispielcode:</p>
<pre><code>if (std::tr1::regex_match(string.c_str(), std::tr1::regex(&quot;([0-9]+)&quot;)))
</code></pre>
<p>(ist jetzt nicht der sauberste Code, also bitte verzeihen.. kannst auch auf spezifische Buchstaben usw überprüfen..</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2296437</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2296437</guid><dc:creator><![CDATA[An0nym0us]]></dc:creator><pubDate>Wed, 06 Feb 2013 12:29:42 GMT</pubDate></item><item><title><![CDATA[Reply to [gelöst]Abfrage auf Buchstaben ?! on Wed, 06 Feb 2013 12:44:22 GMT]]></title><description><![CDATA[<p>Also ich verstehe das Problem immer noch nicht, was ist überhaupt gewollt/erwartet und was passiert oO ?!</p>
<p>Das sollte der TE mal klären...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2296439</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2296439</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Wed, 06 Feb 2013 12:44:22 GMT</pubDate></item><item><title><![CDATA[Reply to [gelöst]Abfrage auf Buchstaben ?! on Mon, 18 Feb 2013 08:01:59 GMT]]></title><description><![CDATA[<p>Naja, das Problem ist, dass ich eine Koordinate haben will, also &quot;A0&quot; -&gt; klappt alles, doch wenn ich &quot;a&quot; oder nur &quot;0&quot; eingebe, stürzt das problem ab...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2299641</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2299641</guid><dc:creator><![CDATA[meinhana]]></dc:creator><pubDate>Mon, 18 Feb 2013 08:01:59 GMT</pubDate></item><item><title><![CDATA[Reply to [gelöst]Abfrage auf Buchstaben ?! on Mon, 18 Feb 2013 08:46:05 GMT]]></title><description><![CDATA[<p>Du brauchst etwas in der Art:</p>
<pre><code>void Mensch::getkoord(string text, int* zeile, int* spalte)
{
    string input;
    cout &lt;&lt; text &lt;&lt; endl;
    bool eingabeOkay = true;

    do
    {
       cin &gt;&gt; input;
       if(input.size() != 2)
       {
          eingabeOkay = false;
       }
       else
       {
          if(input[0] &gt;= 'a' &amp;&amp; input[0] &lt;= 'j' &amp;&amp;
             input[1] &gt;= '0' &amp;&amp; input[1] &lt;= '9')
               ; //alles gut
          else
             eingabeOkay = false;
       }
     }while(!eingabeOkay);

    *zeile = getzeile(input);
    *spalte = getspalte(input);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2299655</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2299655</guid><dc:creator><![CDATA[Belli]]></dc:creator><pubDate>Mon, 18 Feb 2013 08:46:05 GMT</pubDate></item><item><title><![CDATA[Reply to [gelöst]Abfrage auf Buchstaben ?! on Mon, 18 Feb 2013 10:02:30 GMT]]></title><description><![CDATA[<p>Genauuu <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="🙂"
    /><br />
Mal gucken obs klappt ^^ <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/2764.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--red_heart"
      title="&lt;3"
      alt="❤"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2299666</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2299666</guid><dc:creator><![CDATA[meinhana]]></dc:creator><pubDate>Mon, 18 Feb 2013 10:02:30 GMT</pubDate></item><item><title><![CDATA[Reply to [gelöst]Abfrage auf Buchstaben ?! on Tue, 19 Feb 2013 05:55:27 GMT]]></title><description><![CDATA[<p>geht nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2299855</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2299855</guid><dc:creator><![CDATA[meinhana_off]]></dc:creator><pubDate>Tue, 19 Feb 2013 05:55:27 GMT</pubDate></item><item><title><![CDATA[Reply to [gelöst]Abfrage auf Buchstaben ?! on Tue, 19 Feb 2013 07:43:02 GMT]]></title><description><![CDATA[<p>wiesooooooooo<br />
ne fehlermeldung des compilers wäre schon bisschen besser als &quot;geht nicht&quot;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2299859</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2299859</guid><dc:creator><![CDATA[Bentleyfahrer]]></dc:creator><pubDate>Tue, 19 Feb 2013 07:43:02 GMT</pubDate></item><item><title><![CDATA[Reply to [gelöst]Abfrage auf Buchstaben ?! on Tue, 19 Feb 2013 07:50:44 GMT]]></title><description><![CDATA[<p>Der boolsche Wert muss in der Schleife initialisiert werden:</p>
<pre><code>void Mensch::getkoord(string text, int* zeile, int* spalte)
{
    string input;
    cout &lt;&lt; text &lt;&lt; endl;
    bool eingabeOkay;

    do
    {
       eingabeOkay = true;
       cin &gt;&gt; input;
       if(input.size() != 2)
       {
          eingabeOkay = false;
       }
       else
       {
          if(input[0] &gt;= 'a' &amp;&amp; input[0] &lt;= 'j' &amp;&amp;
             input[1] &gt;= '0' &amp;&amp; input[1] &lt;= '9')
               ; //alles gut
          else
             eingabeOkay = false;
       }
     }while(!eingabeOkay);

    *zeile = getzeile(input);
    *spalte = getspalte(input);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2299861</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2299861</guid><dc:creator><![CDATA[Belli]]></dc:creator><pubDate>Tue, 19 Feb 2013 07:50:44 GMT</pubDate></item><item><title><![CDATA[Reply to [gelöst]Abfrage auf Buchstaben ?! on Tue, 19 Feb 2013 07:59:56 GMT]]></title><description><![CDATA[<p>Das mit dem &quot;geht nicht&quot; hab ich nicht geschrieben !</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2299863</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2299863</guid><dc:creator><![CDATA[meinhana]]></dc:creator><pubDate>Tue, 19 Feb 2013 07:59:56 GMT</pubDate></item><item><title><![CDATA[Reply to [gelöst]Abfrage auf Buchstaben ?! on Tue, 19 Feb 2013 08:06:17 GMT]]></title><description><![CDATA[<p>Ich denke zwar, dass ich gerade auf dem Schlauch stehe und die Problematik nicht sehe aber ich poste dennoch mal:</p>
<pre><code>bool GetCoord(std::string const&amp; Str, unsigned&amp; X, unsigned&amp; Y)
{
    if(Str.size() != 2)
        return false;
    if(!(Str[0] &gt;= 'A' &amp;&amp; Str[0] &lt;= 'J' || Str[0] &gt;= 'a' &amp;&amp; Str[0] &lt;= 'j'))
        return false;
    if(!(Str[1] &gt;= '0' &amp;&amp; Str[1] &lt;= '9'))
        return false;
    X = Str[0] - (Str[0] &gt;= 'a' ? 'a' : 'A');
    Y = Str[1] - '0';
    return true;
}
</code></pre>
<p>Und hier das Anwendungsbeispiel:<br />
<a href="http://ideone.com/fZvTDh" rel="nofollow">http://ideone.com/fZvTDh</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2299865</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2299865</guid><dc:creator><![CDATA[MarcoYolo]]></dc:creator><pubDate>Tue, 19 Feb 2013 08:06:17 GMT</pubDate></item><item><title><![CDATA[Reply to [gelöst]Abfrage auf Buchstaben ?! on Tue, 19 Feb 2013 09:04:14 GMT]]></title><description><![CDATA[<p>Die Antwort von Belli hat funktioniert! Hab noch ein cout eingefügt und alles klasse <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="🙂"
    /><br />
Danke <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2299872</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2299872</guid><dc:creator><![CDATA[meinhana]]></dc:creator><pubDate>Tue, 19 Feb 2013 09:04:14 GMT</pubDate></item></channel></rss>