<?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[Hilfe bei der Problemfindung [Anfänger]]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich bin dabei C++ zu lernen. Um meine jetzigen Kenntnisse zu festigen habe ich begonnen ein kleines Projekt zu Programmieren(Als Zusatz zu den Aufgaben aus den Büchern und Videotrainings etc.)<br />
Nur leider habe ich jetzt ein Problem(keinen Fehler).<br />
Ich Programmiere ein kleines Konsolen RPG und habe für den ersten Step im Spiel ein Training erstellt. Das Target hat 100LP und bekommt pro Angriff 20LP abgezogen. Das funktioniert auch alles. Jetzt möchte ich das wenn die LP 0 erreicht haben eine Nachricht kommt mit:&quot;Glückwunsch du hast das Ziel besiegt&quot;.<br />
Aber immer wenn die LP 0 erreicht haben, dann kann man noch einmal angreifen und die LP auf -20 setzen. Ich weiß einfach nicht wie ich das verhindern kann...<br />
Hier ist mal der Code:</p>
<pre><code class="language-cpp">void training1()
{
    int hit = 20;
    int targetLife;
    char eingabe;

    if( targetLife != 0 )
    {
        for( targetLife = 100; targetLife &gt;= 0; targetLife - 20 )
        {
            cout &lt;&lt; &quot;Um das Ziel anzugreifen, gebe A für Angriff ein: &quot;;
            cin &gt;&gt; eingabe;
            if( eingabe == 'A' )
            {
                targetLife = targetLife - hit;
                cout &lt;&lt; &quot;Treffer! Das Ziel verliert 20LP&quot; &lt;&lt; endl;
                cout &lt;&lt; &quot;Das Ziel hat noch &quot; &lt;&lt; targetLife &lt;&lt; &quot; Lebenspunkte!&quot; &lt;&lt; endl;
            }
            else
            {
                while( eingabe != 'A' )
                {
                    cout &lt;&lt; &quot;Diesen Befehl gibt es nicht!&quot; &lt;&lt; endl;
                    cout &lt;&lt; &quot;Um das Ziel anzugreifen, gebe A für Angriff ein: &quot; &lt;&lt; endl;
                    cin &gt;&gt; eingabe;
                    if( eingabe == 'A' )
                    {
                        targetLife = targetLife - hit;
                        cout &lt;&lt; &quot;Treffer! Das Ziel verliert 20LP&quot; &lt;&lt; endl;
                        cout &lt;&lt; &quot;Das Ziel hat noch &quot; &lt;&lt; targetLife &lt;&lt; &quot; Lebenspunkte!&quot; &lt;&lt; endl;
                    }
                }
            }
        }
    }
    else
    {
        cout &lt;&lt; &quot;Super, du hast das Ziel besiegt!&quot; &lt;&lt; endl;
    }
}
</code></pre>
<p>Bestimmt überseh ich grade irgendwas, was eigt. sofort ins Auge springt..^^<br />
Ich hoffe ihr könnt mir helfen <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>Grüße,</p>
<p>eXoTheNext</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/300731/hilfe-bei-der-problemfindung-anfänger</link><generator>RSS for Node</generator><lastBuildDate>Wed, 12 Aug 2026 16:11:45 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/300731.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 09 Mar 2012 09:48:57 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Hilfe bei der Problemfindung [Anfänger] on Fri, 09 Mar 2012 09:48:57 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich bin dabei C++ zu lernen. Um meine jetzigen Kenntnisse zu festigen habe ich begonnen ein kleines Projekt zu Programmieren(Als Zusatz zu den Aufgaben aus den Büchern und Videotrainings etc.)<br />
Nur leider habe ich jetzt ein Problem(keinen Fehler).<br />
Ich Programmiere ein kleines Konsolen RPG und habe für den ersten Step im Spiel ein Training erstellt. Das Target hat 100LP und bekommt pro Angriff 20LP abgezogen. Das funktioniert auch alles. Jetzt möchte ich das wenn die LP 0 erreicht haben eine Nachricht kommt mit:&quot;Glückwunsch du hast das Ziel besiegt&quot;.<br />
Aber immer wenn die LP 0 erreicht haben, dann kann man noch einmal angreifen und die LP auf -20 setzen. Ich weiß einfach nicht wie ich das verhindern kann...<br />
Hier ist mal der Code:</p>
<pre><code class="language-cpp">void training1()
{
    int hit = 20;
    int targetLife;
    char eingabe;

    if( targetLife != 0 )
    {
        for( targetLife = 100; targetLife &gt;= 0; targetLife - 20 )
        {
            cout &lt;&lt; &quot;Um das Ziel anzugreifen, gebe A für Angriff ein: &quot;;
            cin &gt;&gt; eingabe;
            if( eingabe == 'A' )
            {
                targetLife = targetLife - hit;
                cout &lt;&lt; &quot;Treffer! Das Ziel verliert 20LP&quot; &lt;&lt; endl;
                cout &lt;&lt; &quot;Das Ziel hat noch &quot; &lt;&lt; targetLife &lt;&lt; &quot; Lebenspunkte!&quot; &lt;&lt; endl;
            }
            else
            {
                while( eingabe != 'A' )
                {
                    cout &lt;&lt; &quot;Diesen Befehl gibt es nicht!&quot; &lt;&lt; endl;
                    cout &lt;&lt; &quot;Um das Ziel anzugreifen, gebe A für Angriff ein: &quot; &lt;&lt; endl;
                    cin &gt;&gt; eingabe;
                    if( eingabe == 'A' )
                    {
                        targetLife = targetLife - hit;
                        cout &lt;&lt; &quot;Treffer! Das Ziel verliert 20LP&quot; &lt;&lt; endl;
                        cout &lt;&lt; &quot;Das Ziel hat noch &quot; &lt;&lt; targetLife &lt;&lt; &quot; Lebenspunkte!&quot; &lt;&lt; endl;
                    }
                }
            }
        }
    }
    else
    {
        cout &lt;&lt; &quot;Super, du hast das Ziel besiegt!&quot; &lt;&lt; endl;
    }
}
</code></pre>
<p>Bestimmt überseh ich grade irgendwas, was eigt. sofort ins Auge springt..^^<br />
Ich hoffe ihr könnt mir helfen <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>Grüße,</p>
<p>eXoTheNext</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2190039</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2190039</guid><dc:creator><![CDATA[eXoTheNext]]></dc:creator><pubDate>Fri, 09 Mar 2012 09:48:57 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe bei der Problemfindung [Anfänger] on Fri, 09 Mar 2012 10:06:42 GMT]]></title><description><![CDATA[<p>Ändere</p>
<pre><code class="language-cpp">for( targetLife = 100; targetLife &gt;= 0; targetLife - 20 )
</code></pre>
<p>in</p>
<pre><code class="language-cpp">for( targetLife = 100; targetLife != 0; targetLife - 20 )
</code></pre>
<p>edit: Sorry Logikfehler lol.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2190043</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2190043</guid><dc:creator><![CDATA[[[global:former_user]]]]></dc:creator><pubDate>Fri, 09 Mar 2012 10:06:42 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe bei der Problemfindung [Anfänger] on Fri, 09 Mar 2012 10:08:39 GMT]]></title><description><![CDATA[<p>Scorcher24 schrieb:</p>
<blockquote>
<p>Ändere</p>
<pre><code class="language-cpp">for( targetLife = 100; targetLife &gt;= 0; targetLife - 20 )
</code></pre>
<p>in</p>
<pre><code class="language-cpp">for( targetLife = 100; targetLife == 0; targetLife - 20 )
</code></pre>
</blockquote>
<p>Wenn ich das mache dann Startet das Training garnicht erst. Es kommen erst die Texte, dann sollte das Training starten, aber bei weiteren klicken schließt die Konsole...</p>
<p>Edit: Du warst schneller^^</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2190044</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2190044</guid><dc:creator><![CDATA[eXoTheNext]]></dc:creator><pubDate>Fri, 09 Mar 2012 10:08:39 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe bei der Problemfindung [Anfänger] on Fri, 09 Mar 2012 10:09:00 GMT]]></title><description><![CDATA[<p>Ja, siehe mein Edit. Ist mir eh schon peinlich :p.<br />
Kommt davon wenn man so im vorbeigehen antwortet..<br />
<img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_down"
      title=":-1:"
      alt="👎"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2190045</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2190045</guid><dc:creator><![CDATA[[[global:former_user]]]]></dc:creator><pubDate>Fri, 09 Mar 2012 10:09:00 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe bei der Problemfindung [Anfänger] on Fri, 09 Mar 2012 10:10:19 GMT]]></title><description><![CDATA[<p>Les auch mal das hier:<br />
<a href="http://www.c-plusplus.net/forum/39326" rel="nofollow">http://www.c-plusplus.net/forum/39326</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2190046</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2190046</guid><dc:creator><![CDATA[[[global:former_user]]]]></dc:creator><pubDate>Fri, 09 Mar 2012 10:10:19 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe bei der Problemfindung [Anfänger] on Fri, 09 Mar 2012 10:12:00 GMT]]></title><description><![CDATA[<p>Danke, jetzt geht er nicht mehr in den minus bereich.<br />
Doch erscheint die Nachricht das das Ziel besiegt ist immer noch nicht-<br />
Ist es verkehrt das mit else zu machen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2190048</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2190048</guid><dc:creator><![CDATA[eXoTheNext]]></dc:creator><pubDate>Fri, 09 Mar 2012 10:12:00 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe bei der Problemfindung [Anfänger] on Fri, 09 Mar 2012 10:18:36 GMT]]></title><description><![CDATA[<p>Ganz übersehen.<br />
Ja, ist so verkehrt, weil die Bedingung des if-blocks nur am anfang einmal geprüft wird, wenn die Funktion aufgerufen wird. Setz das einfach nach der for-schleife hin.</p>
<pre><code class="language-cpp">void training1()
{
    int hit = 20;
    int targetLife;
    char eingabe;

    if( targetLife != 0 )
    {
        for( targetLife = 100; targetLife != 0; targetLife - 20 )
        {
            cout &lt;&lt; &quot;Um das Ziel anzugreifen, gebe A für Angriff ein: &quot;;
            cin &gt;&gt; eingabe;
            if( eingabe == 'A' )
            {
                targetLife = targetLife - hit;
                cout &lt;&lt; &quot;Treffer! Das Ziel verliert 20LP&quot; &lt;&lt; endl;
                cout &lt;&lt; &quot;Das Ziel hat noch &quot; &lt;&lt; targetLife &lt;&lt; &quot; Lebenspunkte!&quot; &lt;&lt; endl;
            }
            else
            {
                while( eingabe != 'A' )
                {
                    cout &lt;&lt; &quot;Diesen Befehl gibt es nicht!&quot; &lt;&lt; endl;
                    cout &lt;&lt; &quot;Um das Ziel anzugreifen, gebe A für Angriff ein: &quot; &lt;&lt; endl;
                    cin &gt;&gt; eingabe;
                    if( eingabe == 'A' )
                    {
                        targetLife = targetLife - hit;
                        cout &lt;&lt; &quot;Treffer! Das Ziel verliert 20LP&quot; &lt;&lt; endl;
                        cout &lt;&lt; &quot;Das Ziel hat noch &quot; &lt;&lt; targetLife &lt;&lt; &quot; Lebenspunkte!&quot; &lt;&lt; endl;
                    }
                }
            }
        }
		cout &lt;&lt; &quot;Super, du hast das Ziel besiegt!&quot; &lt;&lt; endl;
    }
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2190049</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2190049</guid><dc:creator><![CDATA[[[global:former_user]]]]></dc:creator><pubDate>Fri, 09 Mar 2012 10:18:36 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe bei der Problemfindung [Anfänger] on Fri, 09 Mar 2012 10:16:34 GMT]]></title><description><![CDATA[<p>Wieso angreifen? Der Gegner verläuft sich eh im Klammerwald...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2190050</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2190050</guid><dc:creator><![CDATA[Swordfish]]></dc:creator><pubDate>Fri, 09 Mar 2012 10:16:34 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe bei der Problemfindung [Anfänger] on Fri, 09 Mar 2012 10:18:07 GMT]]></title><description><![CDATA[<p>Scorcher24 schrieb:</p>
<blockquote>
<p>if-schleife</p>
</blockquote>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2190051</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2190051</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Fri, 09 Mar 2012 10:18:07 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe bei der Problemfindung [Anfänger] on Fri, 09 Mar 2012 10:20:20 GMT]]></title><description><![CDATA[<p>Scorcher24 schrieb:</p>
<blockquote>
<p>Ganz übersehen.<br />
Ja, ist so verkehrt, weil die Bedingung der if-<strong>Abfrage</strong> nur am anfang einmal geprüft wird, wenn die Funktion aufgerufen wird. Setz das einfach nach der for-schleife hin.</p>
<pre><code class="language-cpp">void training1()
{
    int hit = 20;
    int targetLife;
    char eingabe;

    if( targetLife != 0 )
    {
        for( targetLife = 100; targetLife != 0; targetLife - 20 )
        {
            cout &lt;&lt; &quot;Um das Ziel anzugreifen, gebe A für Angriff ein: &quot;;
            cin &gt;&gt; eingabe;
            if( eingabe == 'A' )
            {
                targetLife = targetLife - hit;
                cout &lt;&lt; &quot;Treffer! Das Ziel verliert 20LP&quot; &lt;&lt; endl;
                cout &lt;&lt; &quot;Das Ziel hat noch &quot; &lt;&lt; targetLife &lt;&lt; &quot; Lebenspunkte!&quot; &lt;&lt; endl;
            }
            else
            {
                while( eingabe != 'A' )
                {
                    cout &lt;&lt; &quot;Diesen Befehl gibt es nicht!&quot; &lt;&lt; endl;
                    cout &lt;&lt; &quot;Um das Ziel anzugreifen, gebe A für Angriff ein: &quot; &lt;&lt; endl;
                    cin &gt;&gt; eingabe;
                    if( eingabe == 'A' )
                    {
                        targetLife = targetLife - hit;
                        cout &lt;&lt; &quot;Treffer! Das Ziel verliert 20LP&quot; &lt;&lt; endl;
                        cout &lt;&lt; &quot;Das Ziel hat noch &quot; &lt;&lt; targetLife &lt;&lt; &quot; Lebenspunkte!&quot; &lt;&lt; endl;
                    }
                }
            }
        }
		cout &lt;&lt; &quot;Super, du hast das Ziel besiegt!&quot; &lt;&lt; endl;
    }
}
</code></pre>
</blockquote>
<p>Danke jetzt klappts <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>
]]></description><link>https://www.c-plusplus.net/forum/post/2190053</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2190053</guid><dc:creator><![CDATA[eXoTheNext]]></dc:creator><pubDate>Fri, 09 Mar 2012 10:20:20 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe bei der Problemfindung [Anfänger] on Fri, 09 Mar 2012 10:57:28 GMT]]></title><description><![CDATA[<p>Hab dir hier das ganze mal ein wenig aufgepeppt :D.<br />
Ja, mir war grade langweilig. Geht bestimmt noch besser, aber vllt hilfts ja irgendwie beim lernen...</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;string&gt;
using namespace std;

class WeaponBase
{
public:
	WeaponBase( unsigned int attk, const string&amp; name )
		: m_attack(attk), m_name(name)
	{}

	unsigned int getAttack() const { return m_attack; }
	const string&amp; getName() const { return m_name; }

protected:	
	string m_name;
	unsigned int m_attack;
};

class Enemy
{
public:
	Enemy( unsigned int health, const string&amp; name, WeaponBase w ) 
	   : m_health(health), m_name(name), m_weapon(w)
	{}

	unsigned int getHealth() const { return m_health; }
	const string&amp; getName() const { return m_name;  }
	const WeaponBase&amp; getWeapon() const { return m_weapon; }

	void takeDamage( Enemy&amp; e )
	{
		m_health -= e.getWeapon().getAttack();
	}

	void changeWeapon(WeaponBase w )
	{
		m_weapon = w;
	}

	void changeName( const string&amp; name )
	{
		m_name = name;
	}

protected:
   WeaponBase m_weapon;
   unsigned int m_health;
   string m_name;
};

class Player : public Enemy
{
public:
	Player(const string&amp; name) 
		: Enemy(100, name, WeaponBase(20, &quot;Holzschwert&quot;) )
	{}
};

bool combat(Player&amp; p, Enemy&amp; e)
{
	char input = 0;

	cout &lt;&lt; &quot;----------------------------------------&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;\tEin Kampf!&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;\t&quot; &lt;&lt; p.getName() &lt;&lt; &quot; vs. &quot; &lt;&lt; e.getName() &lt;&lt; endl;
	cout &lt;&lt; &quot;----------------------------------------&quot; &lt;&lt; endl;

	while ( e.getHealth() != 0 &amp;&amp; p.getHealth() != 0 )
	{
		cout &lt;&lt; &quot;a) Angreifen&quot; &lt;&lt; endl;
		cout &lt;&lt; &quot;f) Fliehen&quot; &lt;&lt; endl;
		cin  &gt;&gt; input;
		if ( input == 'a' )
		{
			e.takeDamage( p );
			if ( e.getHealth() != 0 ){				
				cout &lt;&lt; &quot;Treffer! &quot; &lt;&lt; e.getName() &lt;&lt; &quot; hat noch &quot; &lt;&lt; e.getHealth()  &lt;&lt; &quot; Leben&quot; &lt;&lt; endl;
			}

			p.takeDamage( e );
			if ( p.getHealth() != 0 ){
				cout &lt;&lt; &quot;Treffer! &quot; &lt;&lt; p.getName() &lt;&lt; &quot;, sie haben noch &quot; &lt;&lt; p.getHealth()  &lt;&lt; &quot; Leben&quot; &lt;&lt; endl;
			}			
		}
		if ( input == 'f' )
		{
			cout &lt;&lt; p.getName() &lt;&lt; &quot;, sie konnten entkommen.&quot; &lt;&lt; endl;
			p.changeName( p.getName() + string( &quot; der Angsthase&quot; ) );
			break;
		}
	}
	if ( e.getHealth() == 0 ){
		cout &lt;&lt; e.getName()  &lt;&lt; &quot; wurde besiegt!&quot; &lt;&lt; endl;
		return true;
	}
	if ( p.getHealth() == 0 ){
		cout &lt;&lt; &quot;Sie wurden besiegt!&quot; &lt;&lt; endl;
		return false;
	}
}

int main()
{
	char input = 0;
	string name;

	cout &lt;&lt; &quot;Ihr Name: &quot;; 
	cin  &gt;&gt; name;
	Player player(name);

	while ( input != 'q' )
	{
		cout &lt;&lt; player.getName() &lt;&lt; &quot;, bitte w\x84 \bhlen sie eine Aktion: &quot; &lt;&lt; endl;
		cout &lt;&lt; &quot;t) Training&quot; &lt;&lt; endl;
		cout &lt;&lt; &quot;q) Beenden&quot; &lt;&lt; endl;
		cin  &gt;&gt; input;

		switch( input )
		{
			case 't':
			{
				Enemy e( 100, &quot;Trainingspuppe&quot;, WeaponBase(1, &quot;Faust&quot;) );
				combat(player, e);
				break;
			}
			default:
				break;			
		}
	}
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2190065</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2190065</guid><dc:creator><![CDATA[[[global:former_user]]]]></dc:creator><pubDate>Fri, 09 Mar 2012 10:57:28 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe bei der Problemfindung [Anfänger] on Fri, 09 Mar 2012 11:31:47 GMT]]></title><description><![CDATA[<p>OOP habe ich mir noch nicht angeschaut, das kommt erst noch <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="😉"
    /><br />
Sobald ich mich auch damit beschäftige werde ich deinen Code mal genauer angucken, hilft mir bestimmt <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</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2190071</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2190071</guid><dc:creator><![CDATA[eXoTheNext]]></dc:creator><pubDate>Fri, 09 Mar 2012 11:31:47 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe bei der Problemfindung [Anfänger] on Fri, 09 Mar 2012 12:57:31 GMT]]></title><description><![CDATA[<p>Ok, dann will ich euch meinen Murks auch ned vorenthalten:</p>
<pre><code class="language-cpp">#include &lt;string&gt;
#include &lt;iostream&gt;

class character_t {

    friend std::ostream &amp; operator&lt;&lt;(std::ostream&amp;, const character_t&amp;);

    private:
        const std::string name;
        const unsigned int initial_power;
        unsigned int current_power;

    public:
        character_t( const std::string &amp;name, unsigned int power )
            : name(name), initial_power(power), current_power(power)
        {
        }

        operator bool( ) const
        {
            return current_power &gt; 0;
        }

        std::string get_name()
        {
            return name;
        }

        void attack( character_t &amp;victim )
        {
            victim.current_power -= 2;
        }
};

std::ostream &amp; operator&lt;&lt;(std::ostream &amp;os, const character_t &amp;character)
{
    os &lt;&lt; character.name &lt;&lt; &quot; &quot; &lt;&lt; character.current_power &lt;&lt; &quot; / &quot; &lt;&lt; character.initial_power;
    return os;
}

int main()
{
    character_t player( &quot;Spieler&quot;, 10 );
    character_t enemy( &quot;Monsti&quot;, 10 );

    char choice = 0;
    do {

        std::cin &gt;&gt; choice;
        if( std::tolower( choice ) == 'a') {

            player.attack( enemy );
        }

        std::cout &lt;&lt; player &lt;&lt; &quot; - vs - &quot; &lt;&lt; enemy &lt;&lt; &quot;\n&quot; &lt;&lt; std::endl;

    } while( player &amp;&amp; enemy );

    std::cout &lt;&lt; ( player ? player.get_name() : enemy.get_name() ) &lt;&lt; &quot; hat gewonnen!\n\n&quot; &lt;&lt; std::endl;
}
</code></pre>
<p>Wer g'winnt is zumindest klar <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>
]]></description><link>https://www.c-plusplus.net/forum/post/2190093</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2190093</guid><dc:creator><![CDATA[Swordfish]]></dc:creator><pubDate>Fri, 09 Mar 2012 12:57:31 GMT</pubDate></item></channel></rss>