<?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[Totales Problem bin am verzweifeln]]></title><description><![CDATA[<p>Hallo!<br />
Ich habe mal wieder angefangen c++ zu programmieren, aber irgendwie gibt es ein riesen Problem und zwar wird eine Endlosschleife produziert und ich weiß einfach nicht warum!!!! Ich drehe bald durch.</p>
<p>Teil des codes:</p>
<pre><code class="language-cpp">cout &lt;&lt;&quot;Setting default values for seats...&quot;;	
	for(k=241;k&lt;281;k++)//Blöcken werden Reihennummern zugewiesen
	{	
		blck[k].reihe=k-240;
		blck[k].belegt=0;
		blck[k].status1=0;
		blck[k].person=0;

	};
	cout &lt;&lt;&quot;Done&quot;&lt;&lt;endl;
</code></pre>
<p>Hier wird eine Endlosschleife produziert warum???? Keine Ahnung.</p>
<pre><code class="language-cpp">cout &lt;&lt;&quot;Setting default values for seats...&quot;;	
	for(k=241;k&lt;281;k++)//Blöcken werden Reihennummern zugewiesen
	{	
		blck[k].reihe=k-240;
		blck[k].belegt=0;
		//blck[k].status1=0;
		blck[k].person=0;

	};
	cout &lt;&lt;&quot;Done&quot;&lt;&lt;endl;
</code></pre>
<p>Dies produziert keine Endlosschleife! Arg was soll das? Was hat das Array blck mit meinem Schleifenzähler zutun? Im obigen Fall fängt die Schleife immer wieder bei 1 an (obwohl sie ja bei 241 anfängt)</p>
<p>Wer das ganze Programm nochmal sehen möchte:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;cstdlib&gt;
#include &lt;stdlib.h&gt;
#include &lt;time.h&gt;
#include &lt;math.h&gt;
#include &lt;unistd.h&gt;

using namespace std;
struct block{
	int belegt;
	int status1;
	int person;
	int reihe;
};

struct person{
	int reihe;
	int platz;
	int t1;
	int t2;
	int t3;
	int zeit;
	int wait;
};

int main (int argc, char * const argv[]) 
{
	int i;
	int k;
	int r;
	int t;
	long j;
	int ready;
	int tick;
	//Intialisierung
	cout &lt;&lt; &quot;Intializing:&quot;&lt;&lt;endl;
	cout &lt;&lt;&quot;Arrays...&quot;;
	block blck[280];
	person pers[240];
	cout &lt;&lt;&quot;Done&quot;&lt;&lt;endl;	
	cout &lt;&lt;&quot;Random...&quot;;
	srand( (unsigned)time( NULL ) );
	cout &lt;&lt;&quot;Done&quot;&lt;&lt;endl;
	cout &lt;&lt;&quot;Setting default values for passangers...&quot;;
	for (i=1;i&lt;=240;i++)
	{
		k=k+1;
		if (k&gt;6){k=1;r++;}
		pers[i].platz=k;
		pers[i].reihe=r;
		pers[i].t1=1; //Laufzeit
		pers[i].t2=20; //Packzeit
		pers[i].t3=10; //Sitzzeit // noch nicht
		pers[i].zeit=0;
		blck[i].person=i;
		blck[i].belegt=100;
		blck[i].status1=1;
		blck[i].reihe=0;
	};
	cout &lt;&lt;&quot;Done&quot;&lt;&lt;endl;
	cout &lt;&lt;&quot;Setting default values for seats...&quot;;	
	for(k=241;k&lt;281;k++)//Blöcken werden Reihennummern zugewiesen
	{	
		blck[k].reihe=k-240;
		blck[k].belegt=0;
		blck[k].status1=0;
		blck[k].person=0;

	};
	cout &lt;&lt;&quot;Done&quot;&lt;&lt;endl;	
	//Mixen
	cout &lt;&lt;&quot;Setting default values for vars...&quot;;
	ready=0; //Es sitzt noch niemand
	cout &lt;&lt;&quot;Done all intializing&quot;&lt;&lt;endl;
cout&lt;&lt;&quot;Starting&quot;&lt;&lt;endl;
	do
	{
		for(i=280;i&gt;=1;i=i-1)
		{
			if(blck[i].status1!=0)
			{
				if(blck[i].belegt&gt;=100) //Wenn belegt bei 100%, dann ist Person in der Lage weiter zu gehen.
				{
					if(blck[i].status1==1)
					{
						if(blck[i+1].status1==0) //Wenn der nächste Block frei ist, dann:
						{
							//Kann weitergehen und sich, falls richtige Reihe, hinsetzen
							if(blck[i+1].reihe==pers[blck[i].person].reihe)
							{
								blck[i+1].status1=2;
								blck[i+1].belegt=(int)100/pers[blck[i].person].t2;
							}
							else
							{
								blck[i+1].status1=1;
								blck[i+1].belegt=(int)100/pers[blck[i].person].t1;
							}							
							blck[i+1].person=blck[i].person;
							//Alten Block frei machen
							blck[i].status1=0;
							blck[i].belegt=0;
							blck[i].person=0;
						}
						else
						{
							pers[blck[i].person].wait+=(int)100/pers[blck[i].person].t1;
						}
					}
					else if(blck[i].status1==2)
					{
						ready++;
						pers[blck[i].person].zeit=t;
						blck[i].status1=0;
						blck[i].belegt=0;
						blck[i].person=0;
						cout &lt;&lt;&quot;Time: &quot;&lt;&lt;t&lt;&lt; &quot;: Passagier Nr. &quot; &lt;&lt;ready&lt;&lt;&quot; hat Platz genommen. Waitingtime: &quot;&lt;&lt;pers[blck[i].person].wait&lt;&lt;endl;
					}
					else if(blck[i].status1==3)
					{
						//Noch nicht implementiert.
					}
				}
				else  //Belegt ist noch nicht bei 100%
				{
					if (blck[i].status1==1) // Person geht
					{blck[i].belegt+=(int)100/pers[blck[i].person].t1;}
					else if(blck[i].status1==2) //Person packt
					{blck[i].belegt+=(int)100/pers[blck[i].person].t2;}
					else if(blck[i].status1==3) //Person setzt sich
					{blck[i].belegt+=(int)100/pers[blck[i].person].t3;}
				}
			}
		}

	t++;
	cout &lt;&lt;&quot;Time: &quot; &lt;&lt;t;
	}while(ready&lt;240); //Solange noch nicht alle sitzen

return 0;
}

int zufall(int o,int u)
{
	return (int)(((double)rand() / RAND_MAX) * (o + 1 - u) + u);
}
</code></pre>
<p>(Programm ist noch nicht fertig, ist auch egal, was es macht, ich verstehe einfach nicht, wo die Endlosschleife herkommt)</p>
<p>Benutze Ubuntu und diesen g++ compiler. Keine Ahnung, welcher Compiler das nun ist.<br />
Bitte helft mir!!! Ich bin verzweifelt!</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/208002/totales-problem-bin-am-verzweifeln</link><generator>RSS for Node</generator><lastBuildDate>Sun, 11 Oct 2026 10:51:12 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/208002.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 13 Mar 2008 16:48:06 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Totales Problem bin am verzweifeln on Thu, 13 Mar 2008 16:48:06 GMT]]></title><description><![CDATA[<p>Hallo!<br />
Ich habe mal wieder angefangen c++ zu programmieren, aber irgendwie gibt es ein riesen Problem und zwar wird eine Endlosschleife produziert und ich weiß einfach nicht warum!!!! Ich drehe bald durch.</p>
<p>Teil des codes:</p>
<pre><code class="language-cpp">cout &lt;&lt;&quot;Setting default values for seats...&quot;;	
	for(k=241;k&lt;281;k++)//Blöcken werden Reihennummern zugewiesen
	{	
		blck[k].reihe=k-240;
		blck[k].belegt=0;
		blck[k].status1=0;
		blck[k].person=0;

	};
	cout &lt;&lt;&quot;Done&quot;&lt;&lt;endl;
</code></pre>
<p>Hier wird eine Endlosschleife produziert warum???? Keine Ahnung.</p>
<pre><code class="language-cpp">cout &lt;&lt;&quot;Setting default values for seats...&quot;;	
	for(k=241;k&lt;281;k++)//Blöcken werden Reihennummern zugewiesen
	{	
		blck[k].reihe=k-240;
		blck[k].belegt=0;
		//blck[k].status1=0;
		blck[k].person=0;

	};
	cout &lt;&lt;&quot;Done&quot;&lt;&lt;endl;
</code></pre>
<p>Dies produziert keine Endlosschleife! Arg was soll das? Was hat das Array blck mit meinem Schleifenzähler zutun? Im obigen Fall fängt die Schleife immer wieder bei 1 an (obwohl sie ja bei 241 anfängt)</p>
<p>Wer das ganze Programm nochmal sehen möchte:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;cstdlib&gt;
#include &lt;stdlib.h&gt;
#include &lt;time.h&gt;
#include &lt;math.h&gt;
#include &lt;unistd.h&gt;

using namespace std;
struct block{
	int belegt;
	int status1;
	int person;
	int reihe;
};

struct person{
	int reihe;
	int platz;
	int t1;
	int t2;
	int t3;
	int zeit;
	int wait;
};

int main (int argc, char * const argv[]) 
{
	int i;
	int k;
	int r;
	int t;
	long j;
	int ready;
	int tick;
	//Intialisierung
	cout &lt;&lt; &quot;Intializing:&quot;&lt;&lt;endl;
	cout &lt;&lt;&quot;Arrays...&quot;;
	block blck[280];
	person pers[240];
	cout &lt;&lt;&quot;Done&quot;&lt;&lt;endl;	
	cout &lt;&lt;&quot;Random...&quot;;
	srand( (unsigned)time( NULL ) );
	cout &lt;&lt;&quot;Done&quot;&lt;&lt;endl;
	cout &lt;&lt;&quot;Setting default values for passangers...&quot;;
	for (i=1;i&lt;=240;i++)
	{
		k=k+1;
		if (k&gt;6){k=1;r++;}
		pers[i].platz=k;
		pers[i].reihe=r;
		pers[i].t1=1; //Laufzeit
		pers[i].t2=20; //Packzeit
		pers[i].t3=10; //Sitzzeit // noch nicht
		pers[i].zeit=0;
		blck[i].person=i;
		blck[i].belegt=100;
		blck[i].status1=1;
		blck[i].reihe=0;
	};
	cout &lt;&lt;&quot;Done&quot;&lt;&lt;endl;
	cout &lt;&lt;&quot;Setting default values for seats...&quot;;	
	for(k=241;k&lt;281;k++)//Blöcken werden Reihennummern zugewiesen
	{	
		blck[k].reihe=k-240;
		blck[k].belegt=0;
		blck[k].status1=0;
		blck[k].person=0;

	};
	cout &lt;&lt;&quot;Done&quot;&lt;&lt;endl;	
	//Mixen
	cout &lt;&lt;&quot;Setting default values for vars...&quot;;
	ready=0; //Es sitzt noch niemand
	cout &lt;&lt;&quot;Done all intializing&quot;&lt;&lt;endl;
cout&lt;&lt;&quot;Starting&quot;&lt;&lt;endl;
	do
	{
		for(i=280;i&gt;=1;i=i-1)
		{
			if(blck[i].status1!=0)
			{
				if(blck[i].belegt&gt;=100) //Wenn belegt bei 100%, dann ist Person in der Lage weiter zu gehen.
				{
					if(blck[i].status1==1)
					{
						if(blck[i+1].status1==0) //Wenn der nächste Block frei ist, dann:
						{
							//Kann weitergehen und sich, falls richtige Reihe, hinsetzen
							if(blck[i+1].reihe==pers[blck[i].person].reihe)
							{
								blck[i+1].status1=2;
								blck[i+1].belegt=(int)100/pers[blck[i].person].t2;
							}
							else
							{
								blck[i+1].status1=1;
								blck[i+1].belegt=(int)100/pers[blck[i].person].t1;
							}							
							blck[i+1].person=blck[i].person;
							//Alten Block frei machen
							blck[i].status1=0;
							blck[i].belegt=0;
							blck[i].person=0;
						}
						else
						{
							pers[blck[i].person].wait+=(int)100/pers[blck[i].person].t1;
						}
					}
					else if(blck[i].status1==2)
					{
						ready++;
						pers[blck[i].person].zeit=t;
						blck[i].status1=0;
						blck[i].belegt=0;
						blck[i].person=0;
						cout &lt;&lt;&quot;Time: &quot;&lt;&lt;t&lt;&lt; &quot;: Passagier Nr. &quot; &lt;&lt;ready&lt;&lt;&quot; hat Platz genommen. Waitingtime: &quot;&lt;&lt;pers[blck[i].person].wait&lt;&lt;endl;
					}
					else if(blck[i].status1==3)
					{
						//Noch nicht implementiert.
					}
				}
				else  //Belegt ist noch nicht bei 100%
				{
					if (blck[i].status1==1) // Person geht
					{blck[i].belegt+=(int)100/pers[blck[i].person].t1;}
					else if(blck[i].status1==2) //Person packt
					{blck[i].belegt+=(int)100/pers[blck[i].person].t2;}
					else if(blck[i].status1==3) //Person setzt sich
					{blck[i].belegt+=(int)100/pers[blck[i].person].t3;}
				}
			}
		}

	t++;
	cout &lt;&lt;&quot;Time: &quot; &lt;&lt;t;
	}while(ready&lt;240); //Solange noch nicht alle sitzen

return 0;
}

int zufall(int o,int u)
{
	return (int)(((double)rand() / RAND_MAX) * (o + 1 - u) + u);
}
</code></pre>
<p>(Programm ist noch nicht fertig, ist auch egal, was es macht, ich verstehe einfach nicht, wo die Endlosschleife herkommt)</p>
<p>Benutze Ubuntu und diesen g++ compiler. Keine Ahnung, welcher Compiler das nun ist.<br />
Bitte helft mir!!! Ich bin verzweifelt!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1473781</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1473781</guid><dc:creator><![CDATA[svebert]]></dc:creator><pubDate>Thu, 13 Mar 2008 16:48:06 GMT</pubDate></item><item><title><![CDATA[Reply to Totales Problem bin am verzweifeln on Thu, 13 Mar 2008 17:07:49 GMT]]></title><description><![CDATA[<p>Du hast</p>
<pre><code class="language-cpp">block blck[280];
</code></pre>
<p>definiert, also 280 mal blck von 0..279 (in C/C++ sind Arrays imer Nullbasiert). In deiner Schleife greifst du aber auf blck[280] zu und überschreibst das was hinter den Array liegt.</p>
<p>Korrigier das mal, vielleicht geht es dann...</p>
<p>LG<br />
Bernd</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1473793</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1473793</guid><dc:creator><![CDATA[BerndD]]></dc:creator><pubDate>Thu, 13 Mar 2008 17:07:49 GMT</pubDate></item><item><title><![CDATA[Reply to Totales Problem bin am verzweifeln on Thu, 13 Mar 2008 17:13:25 GMT]]></title><description><![CDATA[<p>Dasselbe passiert auch bei person.</p>
<p>svebert schrieb:</p>
<blockquote>
<p>...</p>
<pre><code class="language-cpp">...

int main (int argc, char * const argv[]) 
{
...
	person pers[240];
...
	for (i=1;i&lt;=240;i++)
	{
		k=k+1; // BTW: k ist noch nicht initialisiert
...
		pers[i].platz=k;
</code></pre>
</blockquote>
<p>und: Ja, solche Speicherzugriffsverletzungen können zu solchen Fehlerbildern führen.<br />
Sowas kann man übrigens prima von std::vector prüfen lassen.<br />
1.) &quot;block blck[280];&quot; =&gt; &quot;std::vector&lt;block&gt; blck(280);&quot;<br />
2.) &quot;blck[...]&quot; =&gt; &quot;<a href="http://blck.at" rel="nofollow">blck.at</a>(...)&quot; (std::vector hat zwar auch operator[], aber das braucht keinen boudary check zu machen)<br />
3.) ums Ganze einen try/catch-Block...</p>
<p>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1473796</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1473796</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Thu, 13 Mar 2008 17:13:25 GMT</pubDate></item><item><title><![CDATA[Reply to Totales Problem bin am verzweifeln on Thu, 13 Mar 2008 17:14:59 GMT]]></title><description><![CDATA[<p>DANKE!!!!!!!!!<br />
Ich habe in letzter Zeit Basic programmiert und dort wird dann 0...280 definiert. Nun ist alles klar!<br />
Tschüss!<br />
Sven</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1473800</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1473800</guid><dc:creator><![CDATA[svebert]]></dc:creator><pubDate>Thu, 13 Mar 2008 17:14:59 GMT</pubDate></item><item><title><![CDATA[Reply to Totales Problem bin am verzweifeln on Fri, 14 Mar 2008 09:27:05 GMT]]></title><description><![CDATA[<p>svebert schrieb:</p>
<blockquote>
<p>DANKE!!!!!!!!!<br />
Ich habe in letzter Zeit Basic programmiert und dort wird dann 0...280 definiert. ...</p>
</blockquote>
<p>hmmm, nicht eher 1...280 ?<br />
Ich fände es jedenfalls komisch, in einem Array[280] 281 Elemente zu haben.</p>
<p>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1474133</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1474133</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Fri, 14 Mar 2008 09:27:05 GMT</pubDate></item><item><title><![CDATA[Reply to Totales Problem bin am verzweifeln on Fri, 14 Mar 2008 09:31:57 GMT]]></title><description><![CDATA[<p>Simon2 schrieb:</p>
<blockquote>
<p>svebert schrieb:</p>
<blockquote>
<p>DANKE!!!!!!!!!<br />
Ich habe in letzter Zeit Basic programmiert und dort wird dann 0...280 definiert. ...</p>
</blockquote>
<p>hmmm, nicht eher 1...280 ?<br />
Ich fände es jedenfalls komisch, in einem Array[280] 281 Elemente zu haben.</p>
</blockquote>
<p>Es ist zwar befremdlich, aber wenn Du in (zumindest Visual) Basic Nullbasiert arbeitest (kann man einstellen) und ein Array(280) definierst, hast Du 0..280, also 281 Elemente.</p>
<p>Besonders schlimm ist das dann in <a href="http://VisualBasic.NET" rel="nofollow">VisualBasic.NET</a>, denn dort sind VB-Collections 1-basiert, VB-Arrays 0-basiert wie oben, und die .NET-Collections wiederum so, wie wir es gewohnt sind.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1474136</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1474136</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Fri, 14 Mar 2008 09:31:57 GMT</pubDate></item><item><title><![CDATA[Reply to Totales Problem bin am verzweifeln on Fri, 14 Mar 2008 09:33:48 GMT]]></title><description><![CDATA[<p>Nimm Ada, da kannst Array von und zu machen wie du willst. Neben modularen Datentypen etc. ein sinniges Feature.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1474138</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1474138</guid><dc:creator><![CDATA[Fellhuhn]]></dc:creator><pubDate>Fri, 14 Mar 2008 09:33:48 GMT</pubDate></item><item><title><![CDATA[Reply to Totales Problem bin am verzweifeln on Fri, 14 Mar 2008 09:37:25 GMT]]></title><description><![CDATA[<p>LordJaxom schrieb:</p>
<blockquote>
<p>...Basic Nullbasiert arbeitest (kann man einstellen) ...</p>
</blockquote>
<p><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="😮"
    /> <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="😮"
    /> <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 />
OK - das wusste ich nicht (meine Basic-Zeiten sind schon eeeewig her und waren auch nicht glorreich).</p>
<p>Aber das finde ich ja mal übelst bedenklich, wenn das mal so mal so ist...<br />
Naja, ich werde hoffentlich sowieso nie mehr (ernsthaft) mit Basic arbeiten müssen.<br />
<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>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1474141</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1474141</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Fri, 14 Mar 2008 09:37:25 GMT</pubDate></item></channel></rss>