<?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[Prüfung ob Zahl im Array bereits vorhanden]]></title><description><![CDATA[<p>Hallo,</p>
<p>habe das Problem, dass er nicht überprüft ob die Zahl bereits vorhanden ist.<br />
Es kann natürlich vorkommen, dass zweimal hintereinander die eingegebene Zahl bereits im Array vorkommt. Dies möchte ich genauso ausschließen. Der erste Fall funktioniert einwandfrei. Aber falls die Zahl die bereits vorhanden ist über 21 liegt würde es mir das wieder ignorieren. Ich denke ich müsste einen besseren Algorithmus entwickeln, aber komme leider nicht drauf.</p>
<p>Danke für euere Hilfen im Voraus.</p>
<pre><code>int iEingabe;
    int zahl_bereits_vorhanden = 1;

    void TippzettelAusfuellen(int A[], int const &amp;max){
        cout &lt;&lt; &quot;Fuellen Sie Ihren Tippschein aus: &quot; &lt;&lt; endl;
        for (int i = 0; i &lt; max; i++) {
                cout &lt;&lt; &quot;Zahl &quot; &lt;&lt; (i+1) &lt;&lt; &quot;.: &quot;;
                cin &gt;&gt; iEingabe;
                while (iEingabe &gt; 21) {
                        cout &lt;&lt; &quot;Zahl ueber 21!\n&quot; &lt;&lt; &quot;Eingabe wiederholen!\n&quot;;
                        cin &gt;&gt; iEingabe;
                }
                if (i &gt;= 1) {

                while (zahl_bereits_vorhanden == 1){

                     for (int j = (i-1); j = 0; j--){
                        if (iEingabe == A[j]) {
                            cout &lt;&lt; &quot;Zahl bereits vorhanden!\n&quot; &lt;&lt; &quot;Eingabe wiederholen!\n&quot;;
                            cin &gt;&gt; iEingabe;

                        }
                     }
                     zahl_bereits_vorhanden = 0; 
                }
                A[i] == iEingabe;
                zahl_bereits_vorhanden = 1;
                }
        }            

    };
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/323504/prüfung-ob-zahl-im-array-bereits-vorhanden</link><generator>RSS for Node</generator><lastBuildDate>Wed, 15 Jul 2026 20:11:26 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/323504.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 02 Feb 2014 14:30:24 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Prüfung ob Zahl im Array bereits vorhanden on Sun, 02 Feb 2014 14:31:14 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>habe das Problem, dass er nicht überprüft ob die Zahl bereits vorhanden ist.<br />
Es kann natürlich vorkommen, dass zweimal hintereinander die eingegebene Zahl bereits im Array vorkommt. Dies möchte ich genauso ausschließen. Der erste Fall funktioniert einwandfrei. Aber falls die Zahl die bereits vorhanden ist über 21 liegt würde es mir das wieder ignorieren. Ich denke ich müsste einen besseren Algorithmus entwickeln, aber komme leider nicht drauf.</p>
<p>Danke für euere Hilfen im Voraus.</p>
<pre><code>int iEingabe;
    int zahl_bereits_vorhanden = 1;

    void TippzettelAusfuellen(int A[], int const &amp;max){
        cout &lt;&lt; &quot;Fuellen Sie Ihren Tippschein aus: &quot; &lt;&lt; endl;
        for (int i = 0; i &lt; max; i++) {
                cout &lt;&lt; &quot;Zahl &quot; &lt;&lt; (i+1) &lt;&lt; &quot;.: &quot;;
                cin &gt;&gt; iEingabe;
                while (iEingabe &gt; 21) {
                        cout &lt;&lt; &quot;Zahl ueber 21!\n&quot; &lt;&lt; &quot;Eingabe wiederholen!\n&quot;;
                        cin &gt;&gt; iEingabe;
                }
                if (i &gt;= 1) {

                while (zahl_bereits_vorhanden == 1){

                     for (int j = (i-1); j = 0; j--){
                        if (iEingabe == A[j]) {
                            cout &lt;&lt; &quot;Zahl bereits vorhanden!\n&quot; &lt;&lt; &quot;Eingabe wiederholen!\n&quot;;
                            cin &gt;&gt; iEingabe;

                        }
                     }
                     zahl_bereits_vorhanden = 0; 
                }
                A[i] == iEingabe;
                zahl_bereits_vorhanden = 1;
                }
        }            

    };
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2381127</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2381127</guid><dc:creator><![CDATA[depream]]></dc:creator><pubDate>Sun, 02 Feb 2014 14:31:14 GMT</pubDate></item><item><title><![CDATA[Reply to Prüfung ob Zahl im Array bereits vorhanden on Sun, 02 Feb 2014 14:42:03 GMT]]></title><description><![CDATA[<p>Die Bedingung in Zeile 19 gar keine.</p>
<p>Wenn die Zahl schon im Array ist, kannst du jeden Wert eingeben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2381129</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2381129</guid><dc:creator><![CDATA[DirkB]]></dc:creator><pubDate>Sun, 02 Feb 2014 14:42:03 GMT</pubDate></item><item><title><![CDATA[Reply to Prüfung ob Zahl im Array bereits vorhanden on Sun, 02 Feb 2014 14:57:48 GMT]]></title><description><![CDATA[<p>Verbesserung?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2381134</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2381134</guid><dc:creator><![CDATA[depream]]></dc:creator><pubDate>Sun, 02 Feb 2014 14:57:48 GMT</pubDate></item><item><title><![CDATA[Reply to Prüfung ob Zahl im Array bereits vorhanden on Sun, 02 Feb 2014 15:28:59 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">for (int j = (i-1); j &gt;= 0; j--)
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2381138</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2381138</guid><dc:creator><![CDATA[Th69]]></dc:creator><pubDate>Sun, 02 Feb 2014 15:28:59 GMT</pubDate></item><item><title><![CDATA[Reply to Prüfung ob Zahl im Array bereits vorhanden on Sun, 02 Feb 2014 15:45:53 GMT]]></title><description><![CDATA[<p>Und es bietet sich eine <code>do-while</code> [c]-Schleife an, mit nur einer Stelle für die Eingabe.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2381141</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2381141</guid><dc:creator><![CDATA[DirkB]]></dc:creator><pubDate>Sun, 02 Feb 2014 15:45:53 GMT</pubDate></item><item><title><![CDATA[Reply to Prüfung ob Zahl im Array bereits vorhanden on Tue, 04 Feb 2014 14:23:10 GMT]]></title><description><![CDATA[<p>depream schrieb:</p>
<blockquote>
<p>Verbesserung?</p>
</blockquote>
<pre><code>bool any_of( const int* from, const int* to, int value )
{
    for( ; from != to; ++from )
        if( *from == value )
            return true;
    return false;
}

void TippzettelAusfuellen( int A[], int max )
{
    cout &lt;&lt; &quot;Fuellen Sie Ihren Tippschein aus: &quot; &lt;&lt; endl;
    for( int i=0; i&lt;max; ++i )
    {
        bool ok;
        int iEingabe;
        do
        {
            cout &lt;&lt; &quot;Zahl &quot; &lt;&lt; (i+1) &lt;&lt; &quot;.: &quot;;
            cin &gt;&gt; iEingabe;
            ok = false;
            if( iEingabe &gt; 21 )
                cout &lt;&lt; &quot;Zahl ueber 21!\n&quot;;
            else if( any_of( A, A + i, iEingabe ) )
                cout &lt;&lt; &quot;Zahl bereits vorhanden!\n&quot;;
            else
                ok = true;
            if( !ok )
                cout &lt;&lt; &quot;Eingabe wiederholen!\n&quot;;
        }
        while( !ok );

        A[i] = iEingabe;
    }         
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2381476</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2381476</guid><dc:creator><![CDATA[Werner_logoff]]></dc:creator><pubDate>Tue, 04 Feb 2014 14:23:10 GMT</pubDate></item><item><title><![CDATA[Reply to Prüfung ob Zahl im Array bereits vorhanden on Tue, 04 Feb 2014 16:54:20 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/7393">@Werner</a>: <code>std::find</code> in <code>any_of</code> tuts nicht?<br />
Etwa</p>
<pre><code>bool any_of( const int* first, const int* last, int val )
{
    return std::find(first, last, val) != last;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2381498</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2381498</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Tue, 04 Feb 2014 16:54:20 GMT</pubDate></item><item><title><![CDATA[Reply to Prüfung ob Zahl im Array bereits vorhanden on Tue, 04 Feb 2014 20:47:18 GMT]]></title><description><![CDATA[<p>es gibt auch<a href="http://www.cplusplus.com/reference/algorithm/any_of/" rel="nofollow"> <code>std::any_of</code> </a>; das ist aber ein Template und setzt auf der User-seite Funktoren (z.B. Lambdas) voraus.<br />
Um depream nicht zu verschrecken, habe ich das so gemacht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2381537</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2381537</guid><dc:creator><![CDATA[Werner_logoff]]></dc:creator><pubDate>Tue, 04 Feb 2014 20:47:18 GMT</pubDate></item><item><title><![CDATA[Reply to Prüfung ob Zahl im Array bereits vorhanden on Tue, 04 Feb 2014 21:43:53 GMT]]></title><description><![CDATA[<p>Werner_logoff schrieb:</p>
<blockquote>
<p>es gibt auch<a href="http://www.cplusplus.com/reference/algorithm/any_of/" rel="nofollow"> <code>std::any_of</code> </a>; das ist aber ein Template und setzt auf der User-seite Funktoren (z.B. Lambdas) voraus.<br />
Um depream nicht zu verschrecken, habe ich das so gemacht.</p>
</blockquote>
<p>Hättest einen netten Namen erfinden können, vielleicht <strong>contains</strong>. So belegst Du any_of mit einer Bedeutung, die nichts mit std::any_of zu tun hat, fürchte ich.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2381551</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2381551</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Tue, 04 Feb 2014 21:43:53 GMT</pubDate></item><item><title><![CDATA[Reply to Prüfung ob Zahl im Array bereits vorhanden on Tue, 04 Feb 2014 22:10:51 GMT]]></title><description><![CDATA[<p>volkard schrieb:</p>
<blockquote>
<p>Hättest einen netten Namen erfinden können, vielleicht <strong>contains</strong>. So belegst Du any_of mit einer Bedeutung, die nichts mit std::any_of zu tun hat, fürchte ich.</p>
</blockquote>
<p>Das wollte <strong>ich</strong> schreiben! <code>contains</code> gefiel mir auch viel besser! <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>
<blockquote>
<p>es gibt auch std::any_of; das ist aber ein Template und setzt auf der User-seite Funktoren (z.B. Lambdas) voraus.<br />
Um depream nicht zu verschrecken, habe ich das so gemacht.</p>
</blockquote>
<p>Das ist überhaupt kein Argument. Meine Variante nutzt einen Funktionsaufruf... und dazu noch <code>find</code> , eine der allgemeinsten STL-Algorithmen überhaupt <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/2381555</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2381555</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Tue, 04 Feb 2014 22:10:51 GMT</pubDate></item><item><title><![CDATA[Reply to Prüfung ob Zahl im Array bereits vorhanden on Tue, 04 Feb 2014 22:35:34 GMT]]></title><description><![CDATA[<p>volkard schrieb:</p>
<blockquote>
<p>vielleicht <strong>contains</strong></p>
</blockquote>
<p>Oder gleich knackig kurz &quot;in&quot; <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>ps: Ne, das is natürlich doof. Das is nur verständlich wenn man es infix schreibt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2381558</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2381558</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Tue, 04 Feb 2014 22:35:34 GMT</pubDate></item><item><title><![CDATA[Reply to Prüfung ob Zahl im Array bereits vorhanden on Tue, 04 Feb 2014 23:10:16 GMT]]></title><description><![CDATA[<p>Arcoth schrieb:</p>
<blockquote>
<p><code>find</code> , eine der allgemeinsten STL-Algorithmen überhaupt <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>
</blockquote>
<p>Genau, find ist so allgemein, da gibt es keinen Bedarf für find_if, find_if_not, find_end, find_first_of oder sonst so Spässe.</p>
<p>hustbaer schrieb:</p>
<blockquote>
<p>Oder gleich knackig kurz &quot;in&quot; <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>ps: Ne, das is natürlich doof. Das is nur verständlich wenn man es infix schreibt.</p>
</blockquote>
<p>Wie wärs mit operator&gt;&gt;? &quot;&gt;&gt;&quot; ist dank den IO-Streams ein Synonym für &quot;in&quot;.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2381561</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2381561</guid><dc:creator><![CDATA[find=das neue for]]></dc:creator><pubDate>Tue, 04 Feb 2014 23:10:16 GMT</pubDate></item><item><title><![CDATA[Reply to Prüfung ob Zahl im Array bereits vorhanden on Tue, 04 Feb 2014 23:57:10 GMT]]></title><description><![CDATA[<p>hustbaer schrieb:</p>
<blockquote>
<p>volkard schrieb:</p>
<blockquote>
<p>vielleicht <strong>contains</strong></p>
</blockquote>
<p>Oder gleich knackig kurz &quot;in&quot; <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>
</blockquote>
<p>Noch viel knackiger: &quot;∈&quot;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2381567</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2381567</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Tue, 04 Feb 2014 23:57:10 GMT</pubDate></item><item><title><![CDATA[Reply to Prüfung ob Zahl im Array bereits vorhanden on Wed, 05 Feb 2014 07:50:55 GMT]]></title><description><![CDATA[<p>volkard schrieb:</p>
<blockquote>
<p>Werner_logoff schrieb:</p>
<blockquote>
<p>es gibt auch<a href="http://www.cplusplus.com/reference/algorithm/any_of/" rel="nofollow"> <code>std::any_of</code> </a>; das ist aber ein Template und setzt auf der User-seite Funktoren (z.B. Lambdas) voraus.<br />
Um depream nicht zu verschrecken, habe ich das so gemacht.</p>
</blockquote>
<p>Hättest einen netten Namen erfinden können, vielleicht <strong>contains</strong>. So belegst Du any_of mit einer Bedeutung, die nichts mit std::any_of zu tun hat, fürchte ich.</p>
</blockquote>
<p>... interessant. Kannst Du das näher erläutern, warum hat mein <code>any_of</code> oben nichts mit <code>std::any_of</code> zu tun? Mein Sprachverständnis ist irgendwie ein anderes.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2381576</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2381576</guid><dc:creator><![CDATA[Werner_logoff]]></dc:creator><pubDate>Wed, 05 Feb 2014 07:50:55 GMT</pubDate></item><item><title><![CDATA[Reply to Prüfung ob Zahl im Array bereits vorhanden on Wed, 05 Feb 2014 10:49:19 GMT]]></title><description><![CDATA[<p>Nun, any_of prüft, ob eines der Elemente in der Range eine Bedingung erfüllt, deines prüft einfach ob ein bestimmtes Element existiert. Ist in der Tat recht nah dran.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2381607</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2381607</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Wed, 05 Feb 2014 10:49:19 GMT</pubDate></item><item><title><![CDATA[Reply to Prüfung ob Zahl im Array bereits vorhanden on Wed, 05 Feb 2014 12:31:11 GMT]]></title><description><![CDATA[<p>Arcoth schrieb:</p>
<blockquote>
<p>Nun, any_of prüft, ob eines der Elemente in der Range eine Bedingung erfüllt, deines prüft einfach ob ein bestimmtes Element existiert. Ist in der Tat recht nah dran.</p>
</blockquote>
<p>so dachte ich bisher auch, aber volkard anscheinend nicht.<br />
Und hustbaer, 'find=das neue for' und Du signalisierten Zustimmung für volkards Bemerkung mit Vorschlägen für alternative Namen - so interpretiere ich das jedenfalls.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2381623</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2381623</guid><dc:creator><![CDATA[Werner_logoff]]></dc:creator><pubDate>Wed, 05 Feb 2014 12:31:11 GMT</pubDate></item><item><title><![CDATA[Reply to Prüfung ob Zahl im Array bereits vorhanden on Wed, 05 Feb 2014 12:37:06 GMT]]></title><description><![CDATA[<p>Arcoth schrieb:</p>
<blockquote>
<p>Nun, any_of prüft, ob eines der Elemente in der Range eine Bedingung erfüllt, deines prüft einfach ob ein bestimmtes Element existiert. Ist in der Tat recht nah dran.</p>
</blockquote>
<p>Da wäre der Name <code>any_of_if</code> passender, wenn man sich an die Namen anderen STL Funktionen anlehnen möchte.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2381624</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2381624</guid><dc:creator><![CDATA[DocShoe]]></dc:creator><pubDate>Wed, 05 Feb 2014 12:37:06 GMT</pubDate></item><item><title><![CDATA[Reply to Prüfung ob Zahl im Array bereits vorhanden on Wed, 05 Feb 2014 13:17:40 GMT]]></title><description><![CDATA[<p>Werner_logoff schrieb:</p>
<blockquote>
<p>Und hustbaer, 'find=das neue for' und Du signalisierten Zustimmung für volkards Bemerkung mit Vorschlägen für alternative Namen - so interpretiere ich das jedenfalls.</p>
</blockquote>
<p>Ich verstehe nicht was du mir sagen willst.<br />
'find=das neue for'?<br />
WTF?<br />
Und wo du Zustimmung siehst ist nur ein Scherz.</p>
<p>Bin verwirrt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2381631</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2381631</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Wed, 05 Feb 2014 13:17:40 GMT</pubDate></item></channel></rss>