<?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[Variable aus get_ in int (main) benutzen]]></title><description><![CDATA[<p>Hey...</p>
<p>Wie kann ich ich eine Variable aus</p>
<pre><code class="language-cpp">class Gegner
{
	public :

	char name[30];
	int kraft;
	int leben;
	bool waffe;
	bool zustand;
//voids//

	void set_name()
	{
	 cout&lt;&lt;&quot;Wie soll dein Gegner heißen?\n&quot;;
	 cin&gt;&gt;name;

	 cout&lt;&lt;&quot;Dein Gegner heißt &quot;&lt;&lt;name&lt;&lt;&quot;.\n&quot;;
	};
	void get_kraft()
	{
	int zufall = rand() % 100;
	};
	void get_leben()
	{
	int zufall2 = rand() % 130;
	};

//Funktionen//
public :

	void attack();
	void callname();
	void drive();

};
</code></pre>
<p>die beiden int's Zufall und Zufall2 hier einsetzen</p>
<pre><code class="language-cpp">{

	//  int main   //
Krieger Malarkey;
Gegner Hulk;
Malarkey.set_leben(); 
Malarkey.set_kraft(); 
Malarkey.show_leben();
Malarkey.show_kraft();
cout&lt;&lt;&quot;Bereit für das Duell?&quot;&lt;&lt;endl;

cout&lt;&lt;&quot; HIER SOLL DANN IM COUT EINE BERECHUNG MIT DEN BEIDEN WERTEN STATTFINDEN!!!!!&quot;;

getch();
return 0;
}
</code></pre>
<p>Danke schonmal <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>
]]></description><link>https://www.c-plusplus.net/forum/topic/276185/variable-aus-get_-in-int-main-benutzen</link><generator>RSS for Node</generator><lastBuildDate>Wed, 26 Aug 2026 11:47:31 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/276185.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 28 Oct 2010 13:47:05 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Variable aus get_ in int (main) benutzen on Thu, 28 Oct 2010 13:47:05 GMT]]></title><description><![CDATA[<p>Hey...</p>
<p>Wie kann ich ich eine Variable aus</p>
<pre><code class="language-cpp">class Gegner
{
	public :

	char name[30];
	int kraft;
	int leben;
	bool waffe;
	bool zustand;
//voids//

	void set_name()
	{
	 cout&lt;&lt;&quot;Wie soll dein Gegner heißen?\n&quot;;
	 cin&gt;&gt;name;

	 cout&lt;&lt;&quot;Dein Gegner heißt &quot;&lt;&lt;name&lt;&lt;&quot;.\n&quot;;
	};
	void get_kraft()
	{
	int zufall = rand() % 100;
	};
	void get_leben()
	{
	int zufall2 = rand() % 130;
	};

//Funktionen//
public :

	void attack();
	void callname();
	void drive();

};
</code></pre>
<p>die beiden int's Zufall und Zufall2 hier einsetzen</p>
<pre><code class="language-cpp">{

	//  int main   //
Krieger Malarkey;
Gegner Hulk;
Malarkey.set_leben(); 
Malarkey.set_kraft(); 
Malarkey.show_leben();
Malarkey.show_kraft();
cout&lt;&lt;&quot;Bereit für das Duell?&quot;&lt;&lt;endl;

cout&lt;&lt;&quot; HIER SOLL DANN IM COUT EINE BERECHUNG MIT DEN BEIDEN WERTEN STATTFINDEN!!!!!&quot;;

getch();
return 0;
}
</code></pre>
<p>Danke schonmal <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>
]]></description><link>https://www.c-plusplus.net/forum/post/1971948</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1971948</guid><dc:creator><![CDATA[Malcom764]]></dc:creator><pubDate>Thu, 28 Oct 2010 13:47:05 GMT</pubDate></item><item><title><![CDATA[Reply to Variable aus get_ in int (main) benutzen on Thu, 28 Oct 2010 13:50:23 GMT]]></title><description><![CDATA[<p>Gar nicht. Das sind lokale Variablen, die nur innerhalb ihrer jeweiligen Methode existieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1971950</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1971950</guid><dc:creator><![CDATA[Belli]]></dc:creator><pubDate>Thu, 28 Oct 2010 13:50:23 GMT</pubDate></item><item><title><![CDATA[Reply to Variable aus get_ in int (main) benutzen on Thu, 28 Oct 2010 13:59:13 GMT]]></title><description><![CDATA[<p>Ja aber es wird doch wohl irgendwie möglich sein mit ihnen zu rechnen oder?</p>
<p>Also ich habe 2 Zufallswerte aus der Klasse Gegner und 2 werte aus der Klasse Krieger. Will nun in der int main die differenz zwischen den Werten berechnen. Wird doch irgendwie möglich sein oder?</p>
<p>Hier der komplette Code. Unten in der int main soll dann leben aus krieger::Malarkey minus gegner.hulk zufall gerechnet werden. Doch wie geht das??</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;conio.h&gt;

using namespace std;

class Krieger
{

// variablen //

public :

	char name[30];
	int kraft;
	int leben;
	bool waffe;
	bool zustand;

//Funktionen//
public :

	void attack();
	void callname();
	void drive();

//Setvariablen
void set_leben()
{
cout&lt;&lt;&quot;Gebe das Leben deines Kriegers ein!&quot;&lt;&lt;endl;
cin&gt;&gt; leben;

};
void set_kraft() 
{
cout&lt;&lt;&quot;Gebe die Kraft deines Kriegers ein!&quot;&lt;&lt;endl;
cin&gt;&gt; kraft;

};
void set_name();
void set_waffe();
void set_zustand();

//ShowFunktion//
void show_leben(){
	cout&lt;&lt;&quot;Das Leben deines Kriegers ist: &quot;&lt;&lt; leben &lt;&lt;endl;
}
void show_kraft(){
cout&lt;&lt;&quot;Die Kraft deines Kriegers ist: &quot;&lt;&lt; kraft &lt;&lt;endl;
}
};

class Gegner
{
	public :

	char name[30];
	int kraft;
	int leben;
	bool waffe;
	bool zustand;
//voids//

	void set_name()
	{
	 cout&lt;&lt;&quot;Wie soll dein Gegner heißen?\n&quot;;
	 cin&gt;&gt;name;

	 cout&lt;&lt;&quot;Dein Gegner heißt &quot;&lt;&lt;name&lt;&lt;&quot;.\n&quot;;
	};
	void show_kraft(){
	int zufall = rand() % 100;
	cout&lt;&lt;zufall&lt;&lt;endl;
	}

//Funktionen//
public :

	void attack();
	void callname();
	void drive();

};

int main() 

{

	//  int main   //
Krieger Malarkey;
Gegner Hulk;
Malarkey.set_leben(); 
Malarkey.set_kraft(); 
Malarkey.show_leben();
Malarkey.show_kraft();
Hulk.show_kraft();
cout&lt;&lt;&quot;Bereit für das Duell?&quot;&lt;&lt;endl;
getch();

getch();
return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1971956</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1971956</guid><dc:creator><![CDATA[Dingsdadums]]></dc:creator><pubDate>Thu, 28 Oct 2010 13:59:13 GMT</pubDate></item><item><title><![CDATA[Reply to Variable aus get_ in int (main) benutzen on Thu, 28 Oct 2010 14:04:08 GMT]]></title><description><![CDATA[<p>Ich hab jetzt leider keine Zeit mehr (Feierabend :-)), aber in Deinem 'kompletten Code' tauchen die Methoden in der Klasse Gegner aus Deinem Eingangsposting doch gar nicht mehr auf, oder habe ich das jetzt übersehen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1971959</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1971959</guid><dc:creator><![CDATA[Belli]]></dc:creator><pubDate>Thu, 28 Oct 2010 14:04:08 GMT</pubDate></item><item><title><![CDATA[Reply to Variable aus get_ in int (main) benutzen on Thu, 28 Oct 2010 14:59:23 GMT]]></title><description><![CDATA[<p>Da fehlt soooo viel Grundlage. Am besten du nimmst dir dein C++ Buch vor und arbeitest das Kapitel über Funktionen, Parameter und Rückgabewerte noch einmal durch. Und mach´ auch die Übungsaufgaben am Ende des Kapitels!<br />
Es macht mMn wenig Sinn dir jetzt zu erklären, wie man das Problem in deinem Code löst, da das ganze Design kompletter Murks ist (nimm´s bitte nicht persönlich).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1971986</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1971986</guid><dc:creator><![CDATA[DocShoe]]></dc:creator><pubDate>Thu, 28 Oct 2010 14:59:23 GMT</pubDate></item><item><title><![CDATA[Reply to Variable aus get_ in int (main) benutzen on Thu, 28 Oct 2010 15:57:43 GMT]]></title><description><![CDATA[<p>o.O Das hab ich aus dem Buch</p>
<p>C++ Von A bis Z Von Jürgen Wolf!!! Totaler Murks? Ok?!</p>
<p>hm, andere Frage:</p>
<p>habe hier den Code und der findet ein unerwartetes Dateiende?!!?! Doch wieso?! Hab eigentlich doch alle Klammern richtig gesetzt...</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;conio.h&gt;
#include &lt;time.h&gt; 
#include &lt;windows.h&gt; 

using namespace std;

class Krieger
{

// variablen //

public :

	char name[30];
	int kraft;
	int leben;
	bool waffe;
	bool zustand;

//Funktionen//
public :

	void attack();
	void callname();
	void drive();

//Setvariablen

void set_name();
void set_waffe();
void set_zustand();

//ShowFunktion//
void show_leben()
{
	cout&lt;&lt;&quot;Das Leben deines Kriegers ist: 100&quot;&lt;&lt;endl;
	cout&lt;&lt;&quot;Die Kraft deines Kriegers ist: 100&quot;&lt;&lt;endl;
}
void show_kampf()
{
	// INTEGER //
	int gLeben, gKraft, gDiff, gImpo, iDiff, iImpo, iLeben, iKraft, atk1, atk2;
	srand(GetTickCount());
	gLeben = rand()%200;
	gImpo = rand()%200;
	iImpo = 100;
	iLeben = 100;
	iKraft = 100;
	atk1 = iLeben-gKraft;
	atk2 = gLeben-iKraft;
	// INTERGER ENDE//

    cout &lt;&lt;&quot;Das Leben von deinem Gegner = &quot;&lt;&lt;gLeben&lt;&lt;endl;
	Sleep (1000);
	cout&lt;&lt;&quot;Das Leben von deinem Krieger: &quot;&lt;&lt;iLeben&lt;&lt;&quot;\n&quot;;
	Sleep (1000);
	gKraft = rand()%200;
	cout&lt;&lt;&quot;Die Stärke von deinem Krieger: &quot;&lt;&lt;iKraft&lt;&lt;&quot;\n&quot;;
	Sleep (1000);
	cout&lt;&lt;&quot;Die Stärke von deinem Gegner: &quot;&lt;&lt;gKraft&lt;&lt;&quot;\n&quot;;
	cout&lt;&lt;&quot;Deine Imposanz: &quot;&lt;&lt;iImpo&lt;&lt;&quot;.\n&quot;;
	cout&lt;&lt;&quot;Die Imposanz des Gegners: &quot;&lt;&lt;gImpo&lt;&lt;&quot;.\n&quot;;
	if (gImpo&gt;iImpo)
	{

		cout&lt;&lt;&quot;Dein Gegner ist Imposanter! Daher beginnt er mit dem ersten Angriff!\n&quot;;
		cout&lt;&lt;&quot;Der Gegner greift mit einer Stärke von von &quot;&lt;&lt;gKraft&lt;&lt;&quot; an.\n&quot;;

		if (atk1&gt;0)
		{
			cout&lt;&lt;&quot;Dein Leben sinkt auf &quot;&lt;&lt;atk1&lt;&lt;&quot;.\n&quot;;
			cout&lt;&lt;&quot;Du startest nun zum Gegenangriff!\n&quot;;
			cout&lt;&lt;&quot;Das Leben deines Gegners sinkt auf &quot;&lt;&lt;atk2&lt;&lt;&quot;.\n&quot;;
			if(atk2&lt;0)
			{
			cout&lt;&lt;&quot;Dein Gegner fällt ihn Ohnmacht. Du hast gewonnen!\n&quot;;
			}
			else 
			{
				if (atk1&lt;atk2)
				{
				cout&lt;&lt;&quot;Du bist schwächer als er und gibst auf. Der Gegner hat gewonnen!\n&quot;;
				}
				else 
				{
				cout&lt;&lt;&quot;Dein Gegner ist schwächer als du. Du hast gewonnen!\n&quot;;
				}
			}
		}

		if (atk1&lt;0)
		{
		cout&lt;&lt;&quot;Du bist Ohnmaechtig und hast verloren!!\n&quot;;
		}

		}

	if (iImpo&gt;gImpo)
		{
		cout&lt;&lt;&quot;Sein Leben sinkt auf &quot;&lt;&lt;atk2&lt;&lt;&quot;.\n&quot;;
			if(atk2&lt;0)
			{
			cout&lt;&lt;&quot;Dein Gegner fällt ihn Ohnmacht. Du hast gewonnen!\n&quot;;
			}
			else 
			{
				cout&lt;&lt;&quot;Dein Gegner startest nun zum Gegenangriff!\n&quot;;
				cout&lt;&lt;&quot;Dein Leben sinkt auf &quot;&lt;&lt;atk2&lt;&lt;&quot;.\n&quot;;
				if (atk1&lt;atk2)
				{
				cout&lt;&lt;&quot;Du bist schwächer als er und gibst auf. Der Gegner hat gewonnen!\n&quot;;
				}
				else 
				{
				cout&lt;&lt;&quot;Du bist schwächer als dein Gegner und hast verloren!\n&quot;;
				}
			}

		if (atk1&lt;0)
		{
		cout&lt;&lt;&quot;Du bist Ohnmaechtig und hast verloren!!\n&quot;;
		}

	}
};

class Gegner
{
	public :

	char name[30];
//voids//

	void show_name()
	{
	 cout&lt;&lt;&quot;Wie soll dein Gegner heißen?\n&quot;;
	 cin&gt;&gt;name;

	 cout&lt;&lt;&quot;Dein Gegner heißt &quot;&lt;&lt;name&lt;&lt;&quot;.\n&quot;;
	};

//Funktionen//
public :

	void attack();
	void callname();
	void drive();

};

int main() 

{

	//  int main   //
Krieger Malarkey;
Gegner Hulk;
Hulk.show_name();
int gLeben = rand() % 100;
cout&lt;&lt;&quot;Bereit für das Duell?&quot;&lt;&lt;endl;
getch();
Malarkey.show_kampf();
getch();
}
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1972024</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1972024</guid><dc:creator><![CDATA[Dingsdabums]]></dc:creator><pubDate>Thu, 28 Oct 2010 15:57:43 GMT</pubDate></item><item><title><![CDATA[Reply to Variable aus get_ in int (main) benutzen on Thu, 28 Oct 2010 16:57:30 GMT]]></title><description><![CDATA[<p>Dingsdabums schrieb:</p>
<blockquote>
<p>o.O Das hab ich aus dem Buch</p>
<p>C++ Von A bis Z Von Jürgen Wolf!!! Totaler Murks? Ok?!</p>
</blockquote>
<p>Ja. Das Buch ist dafür bekannt, totaler Murks zu sein. Du bestätigst es bloß.</p>
<blockquote>
<p>hm, andere Frage:</p>
<p>habe hier den Code und der findet ein unerwartetes Dateiende?!!?! Doch wieso?! Hab eigentlich doch alle Klammern richtig gesetzt...</p>
</blockquote>
<p>Was soll da schon die Antwort sein? Natürlich sind die Klammern falsch, dies fällt doch sogar bei deiner manuellen Einrückung sofort auf. Guck dir alleine mal die letzte Zeile an und suche die öffnende Klammer.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1972046</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1972046</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Thu, 28 Oct 2010 16:57:30 GMT</pubDate></item><item><title><![CDATA[Reply to Variable aus get_ in int (main) benutzen on Thu, 28 Oct 2010 17:02:36 GMT]]></title><description><![CDATA[<p>Und jetzt? Visual Studio markiert immer di edazugehörige Klammer und meint, die letzte klammer ist mit Gegenstück, eine kweite rnicht mehr...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1972048</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1972048</guid><dc:creator><![CDATA[dgdgdh]]></dc:creator><pubDate>Thu, 28 Oct 2010 17:02:36 GMT</pubDate></item><item><title><![CDATA[Reply to Variable aus get_ in int (main) benutzen on Thu, 28 Oct 2010 17:57:39 GMT]]></title><description><![CDATA[<p>dgdgdh schrieb:</p>
<blockquote>
<p>Und jetzt? Visual Studio markiert immer di edazugehörige Klammer und meint, die letzte klammer ist mit Gegenstück, eine kweite rnicht mehr...</p>
</blockquote>
<p>Ich sag ja auch nicht, dass es kein Gegenstück gibt, sondern dass die Klammern allgemein falsch sind. Ich jage dein Programm mal eben durch einen automatischen Einrücker, dann wird es noch deutlicher:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;conio.h&gt;
#include &lt;time.h&gt;
#include &lt;windows.h&gt;

using namespace std;

class Krieger {

        // variablen //

        public:char name[30];
        int kraft;
        int leben;
        bool waffe;
        bool zustand;

        //Funktionen//
         public: void attack();
        void callname();
        void drive();

        //Setvariablen

        void set_name();
        void set_waffe();
        void set_zustand();

        //ShowFunktion//
        void show_leben() {
                cout &lt;&lt; &quot;Das Leben deines Kriegers ist: 100&quot; &lt;&lt; endl;
                cout &lt;&lt; &quot;Die Kraft deines Kriegers ist: 100&quot; &lt;&lt; endl;
        } void show_kampf() {
                // INTEGER //
                int gLeben, gKraft, gDiff, gImpo, iDiff, iImpo, iLeben, iKraft,
                    atk1, atk2;
                srand(GetTickCount());
                gLeben = rand() % 200;
                gImpo = rand() % 200;
                iImpo = 100;
                iLeben = 100;
                iKraft = 100;
                atk1 = iLeben - gKraft;
                atk2 = gLeben - iKraft;
                // INTERGER ENDE//

                cout &lt;&lt; &quot;Das Leben von deinem Gegner = &quot; &lt;&lt; gLeben &lt;&lt; endl;
                Sleep(1000);
                cout &lt;&lt; &quot;Das Leben von deinem Krieger: &quot; &lt;&lt; iLeben &lt;&lt; &quot;\n&quot;;
                Sleep(1000);
                gKraft = rand() % 200;
                cout &lt;&lt; &quot;Die Stärke von deinem Krieger: &quot; &lt;&lt; iKraft &lt;&lt; &quot;\n&quot;;
                Sleep(1000);
                cout &lt;&lt; &quot;Die Stärke von deinem Gegner: &quot; &lt;&lt; gKraft &lt;&lt; &quot;\n&quot;;
                cout &lt;&lt; &quot;Deine Imposanz: &quot; &lt;&lt; iImpo &lt;&lt; &quot;.\n&quot;;
                cout &lt;&lt; &quot;Die Imposanz des Gegners: &quot; &lt;&lt; gImpo &lt;&lt; &quot;.\n&quot;;
                if (gImpo &gt; iImpo) {

                        cout &lt;&lt;
                            &quot;Dein Gegner ist Imposanter! Daher beginnt er mit dem ersten Angriff!\n&quot;;
                        cout &lt;&lt; &quot;Der Gegner greift mit einer Stärke von von &quot;
                            &lt;&lt; gKraft &lt;&lt; &quot; an.\n&quot;;

                        if (atk1 &gt; 0) {
                                cout &lt;&lt; &quot;Dein Leben sinkt auf &quot; &lt;&lt; atk1 &lt;&lt;
                                    &quot;.\n&quot;;
                                cout &lt;&lt; &quot;Du startest nun zum Gegenangriff!\n&quot;;
                                cout &lt;&lt; &quot;Das Leben deines Gegners sinkt auf &quot; &lt;&lt;
                                    atk2 &lt;&lt; &quot;.\n&quot;;
                                if (atk2 &lt; 0) {
                                        cout &lt;&lt;
                                            &quot;Dein Gegner fällt ihn Ohnmacht. Du hast gewonnen!\n&quot;;
                                } else {
                                        if (atk1 &lt; atk2) {
                                                cout &lt;&lt;
                                                    &quot;Du bist schwächer als er und gibst auf. Der Gegner hat gewonnen!\n&quot;;
                                        } else {
                                                cout &lt;&lt;
                                                    &quot;Dein Gegner ist schwächer als du. Du hast gewonnen!\n&quot;;
                                        }
                                }
                        }

                        if (atk1 &lt; 0) {
                                cout &lt;&lt;
                                    &quot;Du bist Ohnmaechtig und hast verloren!!\n&quot;;
                        }

                }

                if (iImpo &gt; gImpo) {
                        cout &lt;&lt; &quot;Sein Leben sinkt auf &quot; &lt;&lt; atk2 &lt;&lt; &quot;.\n&quot;;
                        if (atk2 &lt; 0) {
                                cout &lt;&lt;
                                    &quot;Dein Gegner fällt ihn Ohnmacht. Du hast gewonnen!\n&quot;;
                        } else {
                                cout &lt;&lt;
                                    &quot;Dein Gegner startest nun zum Gegenangriff!\n&quot;;
                                cout &lt;&lt; &quot;Dein Leben sinkt auf &quot; &lt;&lt; atk2 &lt;&lt;
                                    &quot;.\n&quot;;
                                if (atk1 &lt; atk2) {
                                        cout &lt;&lt;
                                            &quot;Du bist schwächer als er und gibst auf. Der Gegner hat gewonnen!\n&quot;;
                                } else {
                                        cout &lt;&lt;
                                            &quot;Du bist schwächer als dein Gegner und hast verloren!\n&quot;;
                                }
                        }

                        if (atk1 &lt; 0) {
                                cout &lt;&lt;
                                    &quot;Du bist Ohnmaechtig und hast verloren!!\n&quot;;
                        }

                }
        };

        class Gegner {
                public:char name[30];
                //voids//

                void show_name() {
                        cout &lt;&lt; &quot;Wie soll dein Gegner heißen?\n&quot;;
                        cin &gt;&gt; name;

                        cout &lt;&lt; &quot;Dein Gegner heißt &quot; &lt;&lt; name &lt;&lt; &quot;.\n&quot;;
                };

                //Funktionen//
 public:

                void attack();
                void callname();
                void drive();

        };

        int main()
        {

                //  int main   //
                Krieger Malarkey;
                Gegner Hulk;
                Hulk.show_name();
                int gLeben = rand() % 100;
                cout &lt;&lt; &quot;Bereit für das Duell?&quot; &lt;&lt; endl;
                getch();
                Malarkey.show_kampf();
                getch();
        }
}
</code></pre>
<p>Hat eigentlich schon jemand gesagt, dass dein Programm noch zahlreiche andere Fehler enthält? Vermutlich nicht wirklich deine Schuld, schlechter Lehrmeister eben.</p>
<p>edit: Dummer Einrücker hat Tabulatoren benutzt. Dadurch sah es im Forum wie Mist aus. Hier noch einmal in einem Stil, bei dem die falsche Klammerung besonders deutlich wird.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1972066</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1972066</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Thu, 28 Oct 2010 17:57:39 GMT</pubDate></item><item><title><![CDATA[Reply to Variable aus get_ in int (main) benutzen on Thu, 28 Oct 2010 17:53:25 GMT]]></title><description><![CDATA[<p>Welches Buch würdet ihr mir den Empfehlen? Habemir jetzt noch Ensteig in C++ von Willemer bestellt.</p>
<p>Welche haben euch geholfen? Und kannst du mir pls meine Fehler korrigieren? Ich finde sie nicht, tu tmir Leid... Bin heute sehr unkonzentriert...</p>
<p>Grüße,</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1972071</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1972071</guid><dc:creator><![CDATA[Dingsdabums]]></dc:creator><pubDate>Thu, 28 Oct 2010 17:53:25 GMT</pubDate></item><item><title><![CDATA[Reply to Variable aus get_ in int (main) benutzen on Thu, 28 Oct 2010 18:00:04 GMT]]></title><description><![CDATA[<p>Dingsdabums schrieb:</p>
<blockquote>
<p>Welche haben euch geholfen? Und kannst du mir pls meine Fehler korrigieren? Ich finde sie nicht, tu tmir Leid... Bin heute sehr unkonzentriert...</p>
</blockquote>
<p>Nein, da ist zu viel falsch oder schlecht. Das ist mir zu viel Arbeit. Aber vielleicht macht es jemand anderes.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1972075</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1972075</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Thu, 28 Oct 2010 18:00:04 GMT</pubDate></item><item><title><![CDATA[Reply to Variable aus get_ in int (main) benutzen on Thu, 28 Oct 2010 18:05:08 GMT]]></title><description><![CDATA[<p>Hm also, ich meine eigentlich nur das s läuft... Den bis vor dem Gegenüberstellen der Werte gings noch...</p>
<p>Welches Buch würdest du mir den empfehlen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1972076</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1972076</guid><dc:creator><![CDATA[Dingsdabums]]></dc:creator><pubDate>Thu, 28 Oct 2010 18:05:08 GMT</pubDate></item><item><title><![CDATA[Reply to Variable aus get_ in int (main) benutzen on Thu, 28 Oct 2010 19:31:45 GMT]]></title><description><![CDATA[<p>Eventuell &quot;C++ für Spieleprogrammierer von Heiko Kalista&quot; zum Einstieg, da du an diesem Thema ja besonderes Interesse zeigst.</p>
<p>EDIT: Ich habe dir alle Semikolonfehler entfernt und es so verändert, dass es das macht, was du wolltest.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt; 

using namespace std; 

class Krieger 
{ 
public:
    char name[30]; 
    int kraft; 
    int leben; 
    bool waffe; 
    bool zustand; 

public:
	void attack(){}
	void callname(){} 
	void drive(){}

	void set_leben() 
	{ 
		cout &lt;&lt; &quot;Gebe das Leben deines Kriegers ein!&quot; &lt;&lt; endl; 
		cin &gt;&gt; leben; 
	}

	void set_kraft() 
	{ 
		cout &lt;&lt; &quot;Gebe die Kraft deines Kriegers ein!&quot; &lt;&lt; endl; 
		cin &gt;&gt; kraft; 
	}

	void set_name(){}
	void set_waffe(){} 
	void set_zustand(){}

	void show_leben(){ 
		cout &lt;&lt; &quot;Das Leben deines Kriegers ist: &quot; &lt;&lt; leben &lt;&lt; endl; 
	} 

	void show_kraft(){ 
		cout &lt;&lt; &quot;Die Kraft deines Kriegers ist: &quot; &lt;&lt; kraft &lt;&lt; endl; 
	} 
}; 

class Gegner 
{ 
public :
	char name[30]; 
	int kraft; 
	int leben; 
	bool waffe; 
	bool zustand; 

	void set_name() { 
		cout &lt;&lt; &quot;Wie soll dein Gegner heißen?\n&quot;; 
		cin&gt;&gt;name; 

		cout &lt;&lt; &quot;Dein Gegner heißt &quot; &lt;&lt; name &lt;&lt; &quot;.\n&quot;; 
	}

	void show_kraft(){ 
		kraft = rand() % 100; 
		cout &lt;&lt; kraft &lt;&lt; endl; 
	} 

public : 
	void attack(){}
	void callname(){}
	void drive(){}
}; 

int main() 
{ 
	Krieger Malarkey;
	Gegner Hulk;

	Malarkey.set_leben();
	Malarkey.set_kraft();
	Malarkey.show_leben();
	Malarkey.show_kraft();

	Hulk.show_kraft();
	cout &lt;&lt; &quot;Bereit für das Duell?&quot; &lt;&lt; endl;

	Malarkey.leben = Malarkey.leben - Hulk.kraft;

	cout &lt;&lt; &quot;Der Hulk hat angegriffen. Ihr Leben ist nun: &quot; &lt;&lt; Malarkey.leben &lt;&lt; endl;

	cin.get();
	cin.get();
	return 0; 
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1972094</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1972094</guid><dc:creator><![CDATA[HighLigerBiMBam]]></dc:creator><pubDate>Thu, 28 Oct 2010 19:31:45 GMT</pubDate></item><item><title><![CDATA[Reply to Variable aus get_ in int (main) benutzen on Fri, 29 Oct 2010 07:29:38 GMT]]></title><description><![CDATA[<p>Schon wieder ein Jürgen Wolf Opfer <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="😮"
    /><br />
Langsam komme ich zu der Ansicht, dass man ihm verbieten muss Bücher zu schreiben.</p>
<p>Ein paar allgemeine Ratschläge zur Programmierung:</p>
<p>- normalerweise trennt man Datenhaltung und Benutzerinteraktion (Stichwort MVC: Model/View/Controller). In deinem konkreten Fall betrifft das die Methoden set_xxx(), da wird aus der Konsole ein Wert gelesen und einem Attribut zugewiesen. Die Setter Methoden (auch Manipulatoren genannt) sollten nur das Attribut setzen und keinesfalls aus der Konsole lesen:</p>
<pre><code class="language-cpp">class Krieger
{
   unsigned int Kraft_;

   ...

public:
   void setze_kraft( unsigned int Kraft )
   {
      Kraft_ = Kraft;
   }
   ...
};

...
Krieger K;

int Kraft;
cout &lt;&lt; &quot;Bitte Kraft des Kriegers eingeben&quot; &lt;&lt; endl;
cin &gt;&gt; Kraft;

K.setze_kraft( Kraft );
</code></pre>
<p>- die Klassen Krieger und Gegner sind identisch. Warum benötigst du zwei unterschiedliche Klassen, wenn es sich um Objekte mit gleichen Attributen handelt?</p>
<p>- ich finde die Mixtur aus deutschen und englischen Bezeichnern grausamst (Superlativ!). Wenn deutsch, dann ganz deutsch, und wenn englisch, dann ganz englisch. Aber nicht mischen...</p>
<p>Aber besorg´ dir erst ein Mal ein vernünftiges Buch und arbeite das durch.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1972219</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1972219</guid><dc:creator><![CDATA[DocShoe]]></dc:creator><pubDate>Fri, 29 Oct 2010 07:29:38 GMT</pubDate></item><item><title><![CDATA[Reply to Variable aus get_ in int (main) benutzen on Fri, 29 Oct 2010 13:57:41 GMT]]></title><description><![CDATA[<p>Heute ist &quot;Einstieg in C++&quot; von Arnold Willemer eingetrudelt. Kennt ihr das?</p>
<p>Ist das denn wenistens guter Lernstoff?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1972346</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1972346</guid><dc:creator><![CDATA[Dingsibingsi]]></dc:creator><pubDate>Fri, 29 Oct 2010 13:57:41 GMT</pubDate></item><item><title><![CDATA[Reply to Variable aus get_ in int (main) benutzen on Fri, 29 Oct 2010 14:46:26 GMT]]></title><description><![CDATA[<p>Keine Ahnung aber hier gibts sicher gute Bücher: <a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-251551.html" rel="nofollow">http://www.c-plusplus.net/forum/viewtopic-var-t-is-251551.html</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1972376</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1972376</guid><dc:creator><![CDATA[HighLigerBiMBam]]></dc:creator><pubDate>Fri, 29 Oct 2010 14:46:26 GMT</pubDate></item></channel></rss>