<?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]Schiffe versenken]]></title><description><![CDATA[<p>Hey Leute, hab mich jetzt mal am Schiffe versenken geübt,<br />
aber es funktioniert nicht so richtig.<br />
Und zwar funktioniert das Programm wenn ich z.b. nur 1 2er schiff mach ein dreier schiff und kein 4er schiff.<br />
mach ich aber mehr schiffe z.b. ein vierer, dann passiert einfach gar nix mehr und das programm bleibt stehen, mach ich noch mehr schiffe, kommt ein fehler und das programm wird beendet.<br />
vermut mal dass es vll über mein array hinausschreibt, aber ich habe dies eg abgesichert dass es nicht passieren kann.<br />
ich hab mal den langen quellcode gepostet <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="😃"
    /> hoff er ist nicht zu lange und ihr könnt euch durchlesen, falls nicht kann ich gerne auch noch kommentare einfügen, wollt ich eh machen aber wollt erst mal den fehler suchen und dass probier ich schon seit fast 2 stunden <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f621.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--pouting_face"
      title=":rage:"
      alt="😡"
    /></p>
<p>main.cpp</p>
<pre><code class="language-cpp">#include &quot;classBretter.h&quot;

#include &lt;iostream&gt;
#include &lt;iomanip&gt;
#include &lt;string&gt;

using namespace std;

void anzahlZweierSchiffe(Bretter&amp;, const int&amp;, const int&amp;);
void anzahlDreierSchiffe(Bretter&amp;, const int&amp;, const int&amp;);
void anzahlViererSchiffe(Bretter&amp;, const int&amp;, const int&amp;);

const int size1 = 10;
const int size2 = 10;
const int size3 = 4;
bool stop = false;

int main()
{
    cout &lt;&lt; setw(60) &lt;&lt; &quot;Herzlich Willkommen bei Schiffeversenken\n&quot;;
    cout &lt;&lt; &quot;\n&quot;;
    cout &lt;&lt; &quot;\n&quot;;
    cout &lt;&lt; setw(61) &lt;&lt; &quot;Ein '.' bedeutet noch nicht hingeschossen\n&quot;;
    cout &lt;&lt; setw(56) &lt;&lt; &quot;Ein 'X' bedeutet das war nur Wasser\n&quot;;
    cout &lt;&lt; setw(79) &lt;&lt; &quot;Ein 'S' bedeutet da ist ein Schiff, die Klammer sagt wie lang das Schiff ist\n&quot;;
    cout &lt;&lt; &quot;\n\n&quot;;

    Bretter Brett1(size1,size2,size3);
    anzahlZweierSchiffe(Brett1, size1, size2);
    anzahlDreierSchiffe(Brett1, size1, size2);
    anzahlViererSchiffe(Brett1, size1, size2);
    Brett1.brettAusgeben(size1, size2);

    int x;
    int y;

    while(stop == false)
    {
        cout &lt;&lt; &quot;\n&quot;;
        cout &lt;&lt; &quot;Wo moechtest du hinschiessen: x= &quot;;
        cin &gt;&gt; x;
        cout &lt;&lt; &quot;\n&quot;;
        cout &lt;&lt; &quot;Wo moechtest du hinschiessen: y= &quot;;
        cin &gt;&gt; y;
        cout &lt;&lt; &quot;\n&quot;;

    Brett1.check(x,y);
    Brett1.brettAusgeben(size1, size2);
    }
}
</code></pre>
<p>funktionen.cpp</p>
<pre><code class="language-cpp">#include &quot;classBretter.h&quot;
#include &lt;iostream&gt;
#include &lt;iomanip&gt;

using namespace std;

void anzahlZweierSchiffe(Bretter&amp; Brett1, const int&amp; size1, const int&amp; size2)
{
    marke:;
    cout &lt;&lt; &quot;Wie viel zweier Schiffe moechtest du(mindestens 1, maximal 3)&quot;;
    int choice;
    cin &gt;&gt; choice;
    if ((choice &lt; 4) &amp;&amp; (choice &gt; 0))
    {
        for(int i = 0; i &lt; choice; i++)
        {
            Brett1.zweierSchiffeSetzen(size1, size2);
        }
    }
    else
    {
        cout &lt;&lt; &quot;Falsche Eingabe!\n&quot;;
        goto marke;
    }
}

void anzahlDreierSchiffe(Bretter&amp; Brett1, const int&amp; size1, const int&amp; size2)
{
    marke:;
    cout &lt;&lt; &quot;Wie viel dreier Schiffe moechtest du(mindestens 1, maximal 3)&quot;;
    int choice;
    cin &gt;&gt; choice;
    if ((choice &lt; 4) &amp;&amp; (choice &gt; 0))
    {
        for(int i = 0; i &lt; choice; i++)
        {
            Brett1.dreierSchiffeSetzen(size1, size2);
        }
    }
    else
    {
        cout &lt;&lt; &quot;Falsche Eingabe!\n&quot;;
        goto marke;
    }
}

void anzahlViererSchiffe(Bretter&amp; Brett1, const int&amp; size1, const int&amp; size2)
{
    marke:;
    cout &lt;&lt; &quot;Wie viel vierer Schiffe moechtest du(maximal 3)&quot;;
    int choice;
    cin &gt;&gt; choice;
    cout &lt;&lt; &quot;\n\n&quot;;
    if ((choice &lt; 4) &amp;&amp; (choice &gt; 0))
    {
        for(int i = 0; i &lt; choice; i++)
        {
            Brett1.viererSchiffeSetzen(size1, size2);
        }
        cout &lt;&lt; setw(58) &lt;&lt; &quot;Dann kann es ja losgehen!\n&quot;;
    }
    else if (choice == 0)
    {
        cout &lt;&lt; setw(58) &lt;&lt; &quot;Dann kann es ja losgehen!\n&quot;;
    }
    else
    {
        cout &lt;&lt; &quot;Falsche Eingabe!\n&quot;;
        goto marke;
    }
}
</code></pre>
<p>classBretter.h</p>
<pre><code class="language-cpp">#include &lt;string&gt;

#ifndef CLASSBRETTER_H_INCLUDED
#define CLASSBRETTER_H_INCLUDED

class Bretter
{
    public:
        Bretter(const int, const int, const int);
        ~Bretter(){};
        void brettAusgeben(const int&amp;, const int&amp;)const;
        void zweierSchiffeSetzen(const int, const int);
        void dreierSchiffeSetzen(const int, const int);
        void viererSchiffeSetzen(const int, const int);
        void check(int&amp;, int&amp;);

    private:
        std::string Brett[10][10][4];
};

#endif // CLASSBRETTER_H_INCLUDED
</code></pre>
<p>classBretter.cpp</p>
<pre><code class="language-cpp">#include &quot;classBretter.h&quot;

#include &lt;iostream&gt;
#include &lt;iomanip&gt;
#include &lt;string&gt;

using namespace std;

Bretter::Bretter(const int size1, const int size2, const int size3)
{
    for (int i = 0; i &lt; size1; i++)
    {
        for (int j = 0; j &lt; size2; j++)
        {
            Brett[i][j][0] = &quot;.    &quot;;
        }
    }

    for (int i = 0; i &lt; size1; i++)
    {
        for (int j = 0; j &lt; size2; j++)
        {
            Brett[i][j][1] = &quot;0&quot;;
        }
    }

    for (int i = 0; i &lt; size1; i++)
    {
        for (int j = 0; j &lt; size2; j++)
        {
            Brett[i][j][2] = &quot;0&quot;;
        }
    }

    for (int i = 0; i &lt; size1; i++)
    {
        for (int j = 0; j &lt; size2; j++)
        {
            Brett[i][j][3] = &quot;0&quot;;
        }
    }
}

void Bretter::brettAusgeben(const int&amp; size1, const int&amp; size2)const
{
    cout &lt;&lt; setw(67) &lt;&lt; &quot;  0    1    2    3    4    5    6    7    8    9\n&quot;;

    for (int i = 0; i &lt; size1; i++)
    {
        for (int j = 0; j &lt; size2; j++)
        {
            if(j == 0)
            {
                cout &lt;&lt; setw(19) &lt;&lt; i &lt;&lt; &quot; &quot;;
            }
            cout &lt;&lt; Brett[i][j][0];
        }

    cout&lt;&lt;&quot;\n&quot;;
    }
}

void Bretter::zweierSchiffeSetzen(const int size1, const int size2)
{
    srand((unsigned)time(NULL));
    marke:;
    unsigned int x = rand() % size1;
    unsigned int y = rand() % size2;
    if(x+1 &gt; 8)
        {
            goto marke;
        }
    if ((Brett[y][x][2] == &quot;0&quot;) &amp;&amp; (Brett[y][x+1][2] == &quot;0&quot;))
    {
        if(x+1 &gt; 7)
        {
            goto marke;
        }
        for (int i = 0; i &lt; 2; i++)
        {
            Brett[y][x][2] = &quot;1&quot;;
            x++;
        }
        for (int i = 0;i &lt; 2; i++)
        {
            Brett[y][x][3] = &quot;2&quot;;
            x++;
        }
    }
    else
    {
        goto marke;
    }
}

void Bretter::dreierSchiffeSetzen(const int size1, const int size2)
{
    srand((unsigned)time(NULL));
    marke:;
    unsigned int x = rand() % size1;
    unsigned int y = rand() % size2;
    if (y+2 &gt; 7)
        {
            goto marke;
        }
    if ((Brett[y][x][2] == &quot;0&quot;) &amp;&amp; (Brett[y+1][x][2] == &quot;0&quot;) &amp;&amp; (Brett[y+2][x][2] == &quot;0&quot;))
    {
        for (int i = 0; i &lt; 3; i++)
        {
            Brett[y][x][2] = &quot;1&quot;;
            y++;
        }
        for (int i = 0;i &lt; 3; i++)
        {
            Brett[y][x][3] = &quot;3&quot;;
            y++;
        }
    }
    else
    {
     goto marke;
    }
}

void Bretter::viererSchiffeSetzen(const int size1, const int size2)
{
    srand((unsigned)time(NULL));
    marke:;
    unsigned int x = rand() % size1;
    unsigned int y = rand() % size2;
    if(y+3 &gt; 7)
        {
            goto marke;
        }
    if((Brett[y][x][2] == &quot;0&quot;) &amp;&amp; (Brett[y+1][x][2] == &quot;0&quot;) &amp;&amp; (Brett[y+2][x][2] == &quot;0&quot;) &amp;&amp; (Brett[y+3][x][0] == &quot;0&quot;))
    {
        for (int i = 0; i &lt; 4; i++)
        {
            Brett[y][x][2] = &quot;1&quot;;
            y++;
        }
        for (int i = 0;i &lt; 4; i++)
        {
            Brett[y][x][3] = &quot;4&quot;;
            y++;
        }
    }
    else
    {
        goto marke;
    }
}

void Bretter::check(int&amp; x, int&amp; y)
{
    if(Brett[y][x][1] == &quot;0&quot;)
    {
        if(Brett[y][x][2] == &quot;1&quot;)
        {
            if(Brett[y][x][3] == &quot;2&quot;)
            {
                cout &lt;&lt; &quot;Treffer\n&quot;;
                Brett[y][x][0] = &quot;S(2) &quot;;
                Brett[y][x][1] = &quot;1&quot;;
            }
            else if(Brett[y][x][3] == &quot;3&quot;)
            {
                cout &lt;&lt; &quot;Treffer\n&quot;;
                Brett[y][x][0] = &quot;S(3) &quot;;
                Brett[y][x][1] = &quot;1&quot;;
            }
            else if(Brett[y][x][3] == &quot;4&quot;)
            {
                cout &lt;&lt; &quot;Treffer\n&quot;;
                Brett[y][x][0] = &quot;S(4) &quot;;
                Brett[y][x][1] = &quot;1&quot;;
            }
        }
        else
        {
            Brett[y][x][0] = &quot;X    &quot;;
            Brett[y][x][1] = &quot;1&quot;;
            cout &lt;&lt; &quot;Leider nur Wasser\n&quot;;
        }
    }
    else
    {
        cout &lt;&lt; &quot;Dort hast du schonmal hingeschossen\n&quot;;
    }
</code></pre>
<p>Danke schonmal=)</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/259166/gelöst-schiffe-versenken</link><generator>RSS for Node</generator><lastBuildDate>Tue, 08 Sep 2026 21:26:53 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/259166.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 19 Jan 2010 21:10:55 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [gelöst]Schiffe versenken on Fri, 22 Jan 2010 16:52:52 GMT]]></title><description><![CDATA[<p>Hey Leute, hab mich jetzt mal am Schiffe versenken geübt,<br />
aber es funktioniert nicht so richtig.<br />
Und zwar funktioniert das Programm wenn ich z.b. nur 1 2er schiff mach ein dreier schiff und kein 4er schiff.<br />
mach ich aber mehr schiffe z.b. ein vierer, dann passiert einfach gar nix mehr und das programm bleibt stehen, mach ich noch mehr schiffe, kommt ein fehler und das programm wird beendet.<br />
vermut mal dass es vll über mein array hinausschreibt, aber ich habe dies eg abgesichert dass es nicht passieren kann.<br />
ich hab mal den langen quellcode gepostet <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="😃"
    /> hoff er ist nicht zu lange und ihr könnt euch durchlesen, falls nicht kann ich gerne auch noch kommentare einfügen, wollt ich eh machen aber wollt erst mal den fehler suchen und dass probier ich schon seit fast 2 stunden <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f621.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--pouting_face"
      title=":rage:"
      alt="😡"
    /></p>
<p>main.cpp</p>
<pre><code class="language-cpp">#include &quot;classBretter.h&quot;

#include &lt;iostream&gt;
#include &lt;iomanip&gt;
#include &lt;string&gt;

using namespace std;

void anzahlZweierSchiffe(Bretter&amp;, const int&amp;, const int&amp;);
void anzahlDreierSchiffe(Bretter&amp;, const int&amp;, const int&amp;);
void anzahlViererSchiffe(Bretter&amp;, const int&amp;, const int&amp;);

const int size1 = 10;
const int size2 = 10;
const int size3 = 4;
bool stop = false;

int main()
{
    cout &lt;&lt; setw(60) &lt;&lt; &quot;Herzlich Willkommen bei Schiffeversenken\n&quot;;
    cout &lt;&lt; &quot;\n&quot;;
    cout &lt;&lt; &quot;\n&quot;;
    cout &lt;&lt; setw(61) &lt;&lt; &quot;Ein '.' bedeutet noch nicht hingeschossen\n&quot;;
    cout &lt;&lt; setw(56) &lt;&lt; &quot;Ein 'X' bedeutet das war nur Wasser\n&quot;;
    cout &lt;&lt; setw(79) &lt;&lt; &quot;Ein 'S' bedeutet da ist ein Schiff, die Klammer sagt wie lang das Schiff ist\n&quot;;
    cout &lt;&lt; &quot;\n\n&quot;;

    Bretter Brett1(size1,size2,size3);
    anzahlZweierSchiffe(Brett1, size1, size2);
    anzahlDreierSchiffe(Brett1, size1, size2);
    anzahlViererSchiffe(Brett1, size1, size2);
    Brett1.brettAusgeben(size1, size2);

    int x;
    int y;

    while(stop == false)
    {
        cout &lt;&lt; &quot;\n&quot;;
        cout &lt;&lt; &quot;Wo moechtest du hinschiessen: x= &quot;;
        cin &gt;&gt; x;
        cout &lt;&lt; &quot;\n&quot;;
        cout &lt;&lt; &quot;Wo moechtest du hinschiessen: y= &quot;;
        cin &gt;&gt; y;
        cout &lt;&lt; &quot;\n&quot;;

    Brett1.check(x,y);
    Brett1.brettAusgeben(size1, size2);
    }
}
</code></pre>
<p>funktionen.cpp</p>
<pre><code class="language-cpp">#include &quot;classBretter.h&quot;
#include &lt;iostream&gt;
#include &lt;iomanip&gt;

using namespace std;

void anzahlZweierSchiffe(Bretter&amp; Brett1, const int&amp; size1, const int&amp; size2)
{
    marke:;
    cout &lt;&lt; &quot;Wie viel zweier Schiffe moechtest du(mindestens 1, maximal 3)&quot;;
    int choice;
    cin &gt;&gt; choice;
    if ((choice &lt; 4) &amp;&amp; (choice &gt; 0))
    {
        for(int i = 0; i &lt; choice; i++)
        {
            Brett1.zweierSchiffeSetzen(size1, size2);
        }
    }
    else
    {
        cout &lt;&lt; &quot;Falsche Eingabe!\n&quot;;
        goto marke;
    }
}

void anzahlDreierSchiffe(Bretter&amp; Brett1, const int&amp; size1, const int&amp; size2)
{
    marke:;
    cout &lt;&lt; &quot;Wie viel dreier Schiffe moechtest du(mindestens 1, maximal 3)&quot;;
    int choice;
    cin &gt;&gt; choice;
    if ((choice &lt; 4) &amp;&amp; (choice &gt; 0))
    {
        for(int i = 0; i &lt; choice; i++)
        {
            Brett1.dreierSchiffeSetzen(size1, size2);
        }
    }
    else
    {
        cout &lt;&lt; &quot;Falsche Eingabe!\n&quot;;
        goto marke;
    }
}

void anzahlViererSchiffe(Bretter&amp; Brett1, const int&amp; size1, const int&amp; size2)
{
    marke:;
    cout &lt;&lt; &quot;Wie viel vierer Schiffe moechtest du(maximal 3)&quot;;
    int choice;
    cin &gt;&gt; choice;
    cout &lt;&lt; &quot;\n\n&quot;;
    if ((choice &lt; 4) &amp;&amp; (choice &gt; 0))
    {
        for(int i = 0; i &lt; choice; i++)
        {
            Brett1.viererSchiffeSetzen(size1, size2);
        }
        cout &lt;&lt; setw(58) &lt;&lt; &quot;Dann kann es ja losgehen!\n&quot;;
    }
    else if (choice == 0)
    {
        cout &lt;&lt; setw(58) &lt;&lt; &quot;Dann kann es ja losgehen!\n&quot;;
    }
    else
    {
        cout &lt;&lt; &quot;Falsche Eingabe!\n&quot;;
        goto marke;
    }
}
</code></pre>
<p>classBretter.h</p>
<pre><code class="language-cpp">#include &lt;string&gt;

#ifndef CLASSBRETTER_H_INCLUDED
#define CLASSBRETTER_H_INCLUDED

class Bretter
{
    public:
        Bretter(const int, const int, const int);
        ~Bretter(){};
        void brettAusgeben(const int&amp;, const int&amp;)const;
        void zweierSchiffeSetzen(const int, const int);
        void dreierSchiffeSetzen(const int, const int);
        void viererSchiffeSetzen(const int, const int);
        void check(int&amp;, int&amp;);

    private:
        std::string Brett[10][10][4];
};

#endif // CLASSBRETTER_H_INCLUDED
</code></pre>
<p>classBretter.cpp</p>
<pre><code class="language-cpp">#include &quot;classBretter.h&quot;

#include &lt;iostream&gt;
#include &lt;iomanip&gt;
#include &lt;string&gt;

using namespace std;

Bretter::Bretter(const int size1, const int size2, const int size3)
{
    for (int i = 0; i &lt; size1; i++)
    {
        for (int j = 0; j &lt; size2; j++)
        {
            Brett[i][j][0] = &quot;.    &quot;;
        }
    }

    for (int i = 0; i &lt; size1; i++)
    {
        for (int j = 0; j &lt; size2; j++)
        {
            Brett[i][j][1] = &quot;0&quot;;
        }
    }

    for (int i = 0; i &lt; size1; i++)
    {
        for (int j = 0; j &lt; size2; j++)
        {
            Brett[i][j][2] = &quot;0&quot;;
        }
    }

    for (int i = 0; i &lt; size1; i++)
    {
        for (int j = 0; j &lt; size2; j++)
        {
            Brett[i][j][3] = &quot;0&quot;;
        }
    }
}

void Bretter::brettAusgeben(const int&amp; size1, const int&amp; size2)const
{
    cout &lt;&lt; setw(67) &lt;&lt; &quot;  0    1    2    3    4    5    6    7    8    9\n&quot;;

    for (int i = 0; i &lt; size1; i++)
    {
        for (int j = 0; j &lt; size2; j++)
        {
            if(j == 0)
            {
                cout &lt;&lt; setw(19) &lt;&lt; i &lt;&lt; &quot; &quot;;
            }
            cout &lt;&lt; Brett[i][j][0];
        }

    cout&lt;&lt;&quot;\n&quot;;
    }
}

void Bretter::zweierSchiffeSetzen(const int size1, const int size2)
{
    srand((unsigned)time(NULL));
    marke:;
    unsigned int x = rand() % size1;
    unsigned int y = rand() % size2;
    if(x+1 &gt; 8)
        {
            goto marke;
        }
    if ((Brett[y][x][2] == &quot;0&quot;) &amp;&amp; (Brett[y][x+1][2] == &quot;0&quot;))
    {
        if(x+1 &gt; 7)
        {
            goto marke;
        }
        for (int i = 0; i &lt; 2; i++)
        {
            Brett[y][x][2] = &quot;1&quot;;
            x++;
        }
        for (int i = 0;i &lt; 2; i++)
        {
            Brett[y][x][3] = &quot;2&quot;;
            x++;
        }
    }
    else
    {
        goto marke;
    }
}

void Bretter::dreierSchiffeSetzen(const int size1, const int size2)
{
    srand((unsigned)time(NULL));
    marke:;
    unsigned int x = rand() % size1;
    unsigned int y = rand() % size2;
    if (y+2 &gt; 7)
        {
            goto marke;
        }
    if ((Brett[y][x][2] == &quot;0&quot;) &amp;&amp; (Brett[y+1][x][2] == &quot;0&quot;) &amp;&amp; (Brett[y+2][x][2] == &quot;0&quot;))
    {
        for (int i = 0; i &lt; 3; i++)
        {
            Brett[y][x][2] = &quot;1&quot;;
            y++;
        }
        for (int i = 0;i &lt; 3; i++)
        {
            Brett[y][x][3] = &quot;3&quot;;
            y++;
        }
    }
    else
    {
     goto marke;
    }
}

void Bretter::viererSchiffeSetzen(const int size1, const int size2)
{
    srand((unsigned)time(NULL));
    marke:;
    unsigned int x = rand() % size1;
    unsigned int y = rand() % size2;
    if(y+3 &gt; 7)
        {
            goto marke;
        }
    if((Brett[y][x][2] == &quot;0&quot;) &amp;&amp; (Brett[y+1][x][2] == &quot;0&quot;) &amp;&amp; (Brett[y+2][x][2] == &quot;0&quot;) &amp;&amp; (Brett[y+3][x][0] == &quot;0&quot;))
    {
        for (int i = 0; i &lt; 4; i++)
        {
            Brett[y][x][2] = &quot;1&quot;;
            y++;
        }
        for (int i = 0;i &lt; 4; i++)
        {
            Brett[y][x][3] = &quot;4&quot;;
            y++;
        }
    }
    else
    {
        goto marke;
    }
}

void Bretter::check(int&amp; x, int&amp; y)
{
    if(Brett[y][x][1] == &quot;0&quot;)
    {
        if(Brett[y][x][2] == &quot;1&quot;)
        {
            if(Brett[y][x][3] == &quot;2&quot;)
            {
                cout &lt;&lt; &quot;Treffer\n&quot;;
                Brett[y][x][0] = &quot;S(2) &quot;;
                Brett[y][x][1] = &quot;1&quot;;
            }
            else if(Brett[y][x][3] == &quot;3&quot;)
            {
                cout &lt;&lt; &quot;Treffer\n&quot;;
                Brett[y][x][0] = &quot;S(3) &quot;;
                Brett[y][x][1] = &quot;1&quot;;
            }
            else if(Brett[y][x][3] == &quot;4&quot;)
            {
                cout &lt;&lt; &quot;Treffer\n&quot;;
                Brett[y][x][0] = &quot;S(4) &quot;;
                Brett[y][x][1] = &quot;1&quot;;
            }
        }
        else
        {
            Brett[y][x][0] = &quot;X    &quot;;
            Brett[y][x][1] = &quot;1&quot;;
            cout &lt;&lt; &quot;Leider nur Wasser\n&quot;;
        }
    }
    else
    {
        cout &lt;&lt; &quot;Dort hast du schonmal hingeschossen\n&quot;;
    }
</code></pre>
<p>Danke schonmal=)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1841675</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1841675</guid><dc:creator><![CDATA[fr33g]]></dc:creator><pubDate>Fri, 22 Jan 2010 16:52:52 GMT</pubDate></item><item><title><![CDATA[Reply to [gelöst]Schiffe versenken on Tue, 19 Jan 2010 21:34:40 GMT]]></title><description><![CDATA[<p>Gratualtion, du hast dich eben gerade freiwillig dazu gemeldet, zu lernen, wie man einen Debugger benutzt. Erster Schritt: Nach &quot;Debugger&quot; googeln und das Gelernte anwenden. Wenn man das erstmal kann, sind solche Fehler ruckzuck gefunden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1841690</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1841690</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Tue, 19 Jan 2010 21:34:40 GMT</pubDate></item><item><title><![CDATA[Reply to [gelöst]Schiffe versenken on Tue, 19 Jan 2010 21:45:20 GMT]]></title><description><![CDATA[<p>ok danke, werd mal googlen und schaun ob ich was find, werd mich dann nochmal melden;-)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1841701</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1841701</guid><dc:creator><![CDATA[fr33g]]></dc:creator><pubDate>Tue, 19 Jan 2010 21:45:20 GMT</pubDate></item><item><title><![CDATA[Reply to [gelöst]Schiffe versenken on Tue, 19 Jan 2010 21:48:08 GMT]]></title><description><![CDATA[<p>fr33g schrieb:</p>
<blockquote>
<p>ich hab mal den langen quellcode gepostet <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="😃"
    /> hoff er ist nicht zu lange und ihr könnt euch durchlesen,</p>
</blockquote>
<p>Falsch gehofft. Du wusstest doch von Anfang an, dass niemand Lust hat, sich in einen Riesencode von anderen Leuten einzulesen, um deren Fehler zu suchen. Das ist schon deine Sache. Das Forum ist eher da, um konkrete Fragen zu Verständnisproblemen bei C++ zu klären.</p>
<p>fr33g schrieb:</p>
<blockquote>
<p>falls nicht kann ich gerne auch noch kommentare einfügen</p>
</blockquote>
<p>Nein. Falls nicht, bleibt es an dir hängen. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>Aber ich kann dir ein paar Tipps geben. Erstens ist der Debugger, wie SeppJ sagt, eines der wichtigsten Werkzeuge eines Programmierers. Je eher du lernst, mit ihm umzugehen, desto besser. Damit kannst du schrittweise die Variablenwerte deines Programms anschauen und Änderungen nachverfolgen.</p>
<p>Zweitens: Benutze kein <code>goto</code> . Wenn du dich nicht gut mit der Sprache auskennst, ist <code>goto</code> ein heimtükisches, hinterhältiges Sprachmittel. Durch Schleifen und Funktionen ist es in 99% der Fälle unnötig (glaub nicht, dass du zu dem einen Prozent gehörst).</p>
<p>Drittens: Array-Indizes sind immer heikel. Da würde ich beim Fehlersuchen besondere Acht drauf legen. Es kann sich extrem lohnen, einen Wrapper wie <code>std::tr1::array</code> statt rohen Arrays zu verwenden, weil diese Klasse im Debug-Modus Indexprüfungen mit sich bringt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1841704</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1841704</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Tue, 19 Jan 2010 21:48:08 GMT</pubDate></item><item><title><![CDATA[Reply to [gelöst]Schiffe versenken on Tue, 19 Jan 2010 21:52:34 GMT]]></title><description><![CDATA[<p>fr33g schrieb:</p>
<blockquote>
<pre><code class="language-cpp">if(y+3 &gt; 7)
        {
            goto marke;
        }
    if((Brett[y][x][2] == &quot;0&quot;) &amp;&amp; (Brett[y+1][x][2] == &quot;0&quot;) &amp;&amp; (Brett[y+2][x][2] == &quot;0&quot;) &amp;&amp; (Brett[y+3][x][0] == &quot;0&quot;))
    {
        for (int i = 0; i &lt; 4; i++)
        {
...            y++;
        }
        for (int i = 0;i &lt; 4; i++)
        {
...
            y++;
        }
    }
</code></pre>
</blockquote>
<p>Zähle mal nach, wie oft y hier inkrementiert wird. Ständiges srand ist nicht zweckmäßig. goto hilft nicht, den Programmablauf zu erfassen. Zudem ist es sinnvoll zu versuchen, die Erzeugung der Zufallspositionen gleich richtig einzuschänken.</p>
<pre><code class="language-cpp">void Bretter::viererSchiffeSetzen(const int size1, const int size2)
{
    for ( ;; )
    {
        unsigned int x = rand() % size1;
        unsigned int y = rand() % ( size2 - 4 + 1 );
        if(  (Brett[y+0][x][2] == &quot;0&quot;)
          &amp;&amp; (Brett[y+1][x][2] == &quot;0&quot;)
          &amp;&amp; (Brett[y+2][x][2] == &quot;0&quot;)
          &amp;&amp; (Brett[y+3][x][0] == &quot;0&quot;))
        {
            for (int i = 0; i &lt; 4; i++)
            {
                Brett[y+i][x][2] = &quot;1&quot;;
                Brett[y+i][x][3] = &quot;4&quot;;
            }
            return;
        }
    }
}
</code></pre>
<p>Hier scheint sich ein C&amp;P-Fehler eingeschlichen zu haben, der bei ein bisschen Aufmerksamkeit für Formatierung ins Auge sticht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1841706</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1841706</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Tue, 19 Jan 2010 21:52:34 GMT</pubDate></item><item><title><![CDATA[Reply to [gelöst]Schiffe versenken on Tue, 19 Jan 2010 22:08:06 GMT]]></title><description><![CDATA[<p>danke erst mal für die tipps, bin grad noch am googlen wie das mit dem debugger so funzt, es hat net jemand einen guten link grad da?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1841713</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1841713</guid><dc:creator><![CDATA[fr33g]]></dc:creator><pubDate>Tue, 19 Jan 2010 22:08:06 GMT</pubDate></item><item><title><![CDATA[Reply to [gelöst]Schiffe versenken on Tue, 19 Jan 2010 22:46:50 GMT]]></title><description><![CDATA[<p>fr33g schrieb:</p>
<blockquote>
<p>danke erst mal für die tipps, bin grad noch am googlen wie das mit dem debugger so funzt, es hat net jemand einen guten link grad da?</p>
</blockquote>
<p>Oftmals arbeiten Debugger eng mit Entwicklungsumgebung und Compiler zusammen. Welche benutzt du?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1841726</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1841726</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Tue, 19 Jan 2010 22:46:50 GMT</pubDate></item><item><title><![CDATA[Reply to [gelöst]Schiffe versenken on Wed, 20 Jan 2010 06:45:14 GMT]]></title><description><![CDATA[<p>ich benutze code blocks und den gnu compiler.<br />
hoffe ihr könnt mir bissel helfen so dass ich das lernen kann mit dem debuggen=)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1841774</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1841774</guid><dc:creator><![CDATA[fr33g]]></dc:creator><pubDate>Wed, 20 Jan 2010 06:45:14 GMT</pubDate></item><item><title><![CDATA[Reply to [gelöst]Schiffe versenken on Wed, 20 Jan 2010 06:59:51 GMT]]></title><description><![CDATA[<p>hast du deine frage schon mal google gestellt?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1841777</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1841777</guid><dc:creator><![CDATA[g00gler]]></dc:creator><pubDate>Wed, 20 Jan 2010 06:59:51 GMT</pubDate></item><item><title><![CDATA[Reply to [gelöst]Schiffe versenken on Wed, 20 Jan 2010 16:25:18 GMT]]></title><description><![CDATA[<p>ja das habe ich, wollt aber halt auch nochmal hier fragen falls jemand eh nen guten link hat oder es mir gerne auch noch mal erklärt=)<br />
ist ja wohl nicht verboten... <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f62e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_open_mouth"
      title=":open_mouth:"
      alt="😮"
    /></p>
<p>EDIT:<br />
Also hab mal oben die Fehler weggemacht so weit ich sie hoffentlich erkannt habe.<br />
Mein Problem ist jetzt aber immer noch dass ich nichts gescheites beim goggeln find wegen dem debuggen, da steht immer was von wegen befehle irgendwo eingeben...aber des muss doch auch übers menü gehen, aber der hält bei mir net wirklich bei breakpoints und anzeigen tut er au nix variablen werte oder so:(</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1842033</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1842033</guid><dc:creator><![CDATA[fr33g]]></dc:creator><pubDate>Wed, 20 Jan 2010 16:25:18 GMT</pubDate></item><item><title><![CDATA[Reply to [gelöst]Schiffe versenken on Fri, 22 Jan 2010 12:52:49 GMT]]></title><description><![CDATA[<p>camper schrieb:</p>
<blockquote>
<p>fr33g schrieb:</p>
<blockquote>
<pre><code class="language-cpp">if(y+3 &gt; 7)
        {
            goto marke;
        }
    if((Brett[y][x][2] == &quot;0&quot;) &amp;&amp; (Brett[y+1][x][2] == &quot;0&quot;) &amp;&amp; (Brett[y+2][x][2] == &quot;0&quot;) &amp;&amp; (Brett[y+3][x][0] == &quot;0&quot;))
    {
        for (int i = 0; i &lt; 4; i++)
        {
...            y++;
        }
        for (int i = 0;i &lt; 4; i++)
        {
...
            y++;
        }
    }
</code></pre>
</blockquote>
<p>Zähle mal nach, wie oft y hier inkrementiert wird. Ständiges srand ist nicht zweckmäßig. goto hilft nicht, den Programmablauf zu erfassen. Zudem ist es sinnvoll zu versuchen, die Erzeugung der Zufallspositionen gleich richtig einzuschänken.</p>
<pre><code class="language-cpp">void Bretter::viererSchiffeSetzen(const int size1, const int size2)
{
    for ( ;; )
    {
        unsigned int x = rand() % size1;
        unsigned int y = rand() % ( size2 - 4 + 1 );
        if(  (Brett[y+0][x][2] == &quot;0&quot;)
          &amp;&amp; (Brett[y+1][x][2] == &quot;0&quot;)
          &amp;&amp; (Brett[y+2][x][2] == &quot;0&quot;)
          &amp;&amp; (Brett[y+3][x][0] == &quot;0&quot;))
        {
            for (int i = 0; i &lt; 4; i++)
            {
                Brett[y+i][x][2] = &quot;1&quot;;
                Brett[y+i][x][3] = &quot;4&quot;;
            }
            return;
        }
    }
}
</code></pre>
<p>Hier scheint sich ein C&amp;P-Fehler eingeschlichen zu haben, der bei ein bisschen Aufmerksamkeit für Formatierung ins Auge sticht.</p>
</blockquote>
<p>Also mein Programm läuft leider immer noch nicht.<br />
hab mir hier nochmal alles durchgelesen, hab jetzt srand nur noch einmal drin und goto auch weg=)<br />
und deine tipps auch umgesetzt.<br />
blos ich raff des net mit y inkrementieren...ich inkrementiere es doch 4 mal oder? so soll es doch auch sein oder was meinst du?<br />
y, y+1 y+2 y+3 y+4, wobei ja das y+4 dann nicht mehr verwendet wird, daher sind es doch 4 felder oder?</p>
<p>danke schonmal</p>
<p>EDIT:<br />
Danke an alle die mir tipss gegeben haben, habs hinbekommen warn problem mit dem inkrementieren wie ein vorredner schon sagte, dadurch hab ich über das array hinausgeschrieben:D<br />
Das mit dem debuggen check ich zwar no net so wirklich weil trotz einstellungen hält mein debugger nie an an breakpoints...=(</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1843092</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1843092</guid><dc:creator><![CDATA[fr33g]]></dc:creator><pubDate>Fri, 22 Jan 2010 12:52:49 GMT</pubDate></item></channel></rss>