<?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[Unbekannter Fehler (Schaltjahreszählung)]]></title><description><![CDATA[<p>Bisher funktionierte alles einwandfrei:</p>
<p>Jetz habe ich einen Schaltjahreszähler eingebaut, und plötzlich zählt er die Monate mit 30 Tagen doppelt.</p>
<pre><code>#include &lt;iostream&gt;
using namespace std;

int tz=1; //tageszähler
int mo=1; //Monatszähler
int gtz=0; //durchgehender Tageszähler
int kjz; // Kleiner Jahreszähler (Tetraeteris)
int main () 
{

	for (int kjz=1; kjz&lt;5; kjz=kjz+1)
		{

			for(int mo=1; mo&lt;13; mo=mo+1) //Monatszählerschleife
				{
					if (mo==1||mo==3||mo==5||mo==7||mo==8||mo==10||mo==12) //Tageszählerschleife für 31 Tage MONATE
						{
							for(int tz=1; tz&lt;32; tz=tz+1)
								{
								gtz=gtz+1;
								int Tag=Tag+ 1;
								cout&lt;&lt;&quot;TN = &quot;&lt;&lt;gtz&lt;&lt;&quot; Tag &quot; &lt;&lt;tz&lt;&lt;&quot; Monat &quot;&lt;&lt;mo&lt;&lt; &quot; \n&quot;;
								}
								cout&lt;&lt;&quot;MonatSENDE  \n  \n&quot;;
						}
					else
						{
						if (mo==4||mo==6||mo==9||mo==11)
						{
							for(int tz=1; tz&lt;31; tz=tz+1)//Tageszählerschleife für 30 Tage MONATE
								{
								gtz=gtz+1;
								int Tag=Tag+1;
								cout&lt;&lt;&quot;TN = &quot;&lt;&lt;gtz&lt;&lt;&quot; Tag &quot; &lt;&lt;tz&lt;&lt;&quot; Monat &quot;&lt;&lt;mo&lt;&lt; &quot; \n&quot;;
								}
							cout&lt;&lt;&quot;Monatende  \n  \n&quot;;
						}	
					if (mo==2&amp;&amp;kjz==4)
						{
							for(int tz=1; tz&lt;30; tz=tz+1)//Tageszählerschleife für 29 Tage Schaltjahr
								{
								gtz=gtz+1;
								int Tag=Tag+1;
								cout&lt;&lt;&quot;TN = &quot;&lt;&lt;gtz&lt;&lt;&quot; Tag &quot; &lt;&lt;tz&lt;&lt;&quot; Monat &quot;&lt;&lt;mo&lt;&lt; &quot; \n&quot;;
								}
							cout&lt;&lt;&quot;Februar  \n  \n&quot;;
						}
						else
							{
							for(int tz=1; tz&lt;29; tz=tz+1)//Tageszählerschleife für 28 Tage NichtSchaltjahr
								{
								gtz=gtz+1;
								int Tag=Tag+1;
								cout&lt;&lt;&quot;TN = &quot;&lt;&lt;gtz&lt;&lt;&quot; Tag &quot; &lt;&lt;tz&lt;&lt;&quot; Monat &quot;&lt;&lt;mo&lt;&lt; &quot; \n&quot;;
								}
							cout&lt;&lt;&quot;Februar  \n  \n&quot;;
							}	
				}

			}
			cout&lt;&lt;&quot;JAHRESENDE JAHR = &quot; &lt;&lt;kjz&lt;&lt; &quot;\n  \n&quot;;
	}
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/261208/unbekannter-fehler-schaltjahreszählung</link><generator>RSS for Node</generator><lastBuildDate>Mon, 07 Sep 2026 16:31:54 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/261208.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 15 Feb 2010 10:48:21 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Unbekannter Fehler (Schaltjahreszählung) on Mon, 15 Feb 2010 10:48:21 GMT]]></title><description><![CDATA[<p>Bisher funktionierte alles einwandfrei:</p>
<p>Jetz habe ich einen Schaltjahreszähler eingebaut, und plötzlich zählt er die Monate mit 30 Tagen doppelt.</p>
<pre><code>#include &lt;iostream&gt;
using namespace std;

int tz=1; //tageszähler
int mo=1; //Monatszähler
int gtz=0; //durchgehender Tageszähler
int kjz; // Kleiner Jahreszähler (Tetraeteris)
int main () 
{

	for (int kjz=1; kjz&lt;5; kjz=kjz+1)
		{

			for(int mo=1; mo&lt;13; mo=mo+1) //Monatszählerschleife
				{
					if (mo==1||mo==3||mo==5||mo==7||mo==8||mo==10||mo==12) //Tageszählerschleife für 31 Tage MONATE
						{
							for(int tz=1; tz&lt;32; tz=tz+1)
								{
								gtz=gtz+1;
								int Tag=Tag+ 1;
								cout&lt;&lt;&quot;TN = &quot;&lt;&lt;gtz&lt;&lt;&quot; Tag &quot; &lt;&lt;tz&lt;&lt;&quot; Monat &quot;&lt;&lt;mo&lt;&lt; &quot; \n&quot;;
								}
								cout&lt;&lt;&quot;MonatSENDE  \n  \n&quot;;
						}
					else
						{
						if (mo==4||mo==6||mo==9||mo==11)
						{
							for(int tz=1; tz&lt;31; tz=tz+1)//Tageszählerschleife für 30 Tage MONATE
								{
								gtz=gtz+1;
								int Tag=Tag+1;
								cout&lt;&lt;&quot;TN = &quot;&lt;&lt;gtz&lt;&lt;&quot; Tag &quot; &lt;&lt;tz&lt;&lt;&quot; Monat &quot;&lt;&lt;mo&lt;&lt; &quot; \n&quot;;
								}
							cout&lt;&lt;&quot;Monatende  \n  \n&quot;;
						}	
					if (mo==2&amp;&amp;kjz==4)
						{
							for(int tz=1; tz&lt;30; tz=tz+1)//Tageszählerschleife für 29 Tage Schaltjahr
								{
								gtz=gtz+1;
								int Tag=Tag+1;
								cout&lt;&lt;&quot;TN = &quot;&lt;&lt;gtz&lt;&lt;&quot; Tag &quot; &lt;&lt;tz&lt;&lt;&quot; Monat &quot;&lt;&lt;mo&lt;&lt; &quot; \n&quot;;
								}
							cout&lt;&lt;&quot;Februar  \n  \n&quot;;
						}
						else
							{
							for(int tz=1; tz&lt;29; tz=tz+1)//Tageszählerschleife für 28 Tage NichtSchaltjahr
								{
								gtz=gtz+1;
								int Tag=Tag+1;
								cout&lt;&lt;&quot;TN = &quot;&lt;&lt;gtz&lt;&lt;&quot; Tag &quot; &lt;&lt;tz&lt;&lt;&quot; Monat &quot;&lt;&lt;mo&lt;&lt; &quot; \n&quot;;
								}
							cout&lt;&lt;&quot;Februar  \n  \n&quot;;
							}	
				}

			}
			cout&lt;&lt;&quot;JAHRESENDE JAHR = &quot; &lt;&lt;kjz&lt;&lt; &quot;\n  \n&quot;;
	}
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1855817</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1855817</guid><dc:creator><![CDATA[Bekell]]></dc:creator><pubDate>Mon, 15 Feb 2010 10:48:21 GMT</pubDate></item><item><title><![CDATA[Reply to Unbekannter Fehler (Schaltjahreszählung) on Mon, 15 Feb 2010 10:59:53 GMT]]></title><description><![CDATA[<p>Erstmal ordentlich eingerückt:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt; 
using namespace std; 

int tz=1; //tageszähler 
int mo=1; //Monatszähler 
int gtz=0; //durchgehender Tageszähler 
int kjz; // Kleiner Jahreszähler (Tetraeteris) 
int main () 
{ 

    for (int kjz=1; kjz&lt;5; kjz=kjz+1) 
    {
        for(int mo=1; mo&lt;13; mo=mo+1) //Monatszählerschleife 
        { 
            if (mo==1||mo==3||mo==5||mo==7||mo==8||mo==10||mo==12) //Tageszählerschleife für 31 Tage MONATE 
            { 
                for(int tz=1; tz&lt;32; tz=tz+1) 
                { 
                    gtz=gtz+1; 
                    int Tag=Tag+ 1; 
                    cout&lt;&lt;&quot;TN = &quot;&lt;&lt;gtz&lt;&lt;&quot; Tag &quot; &lt;&lt;tz&lt;&lt;&quot; Monat &quot;&lt;&lt;mo&lt;&lt; &quot; \n&quot;; 
                } 
                cout&lt;&lt;&quot;MonatSENDE  \n  \n&quot;; 
            } 
            else 
            { 
                if (mo==4||mo==6||mo==9||mo==11) 
                { 
                    for(int tz=1; tz&lt;31; tz=tz+1)//Tageszählerschleife für 30 Tage MONATE 
                    { 
                        gtz=gtz+1; 
                        int Tag=Tag+1; 
                        cout&lt;&lt;&quot;TN = &quot;&lt;&lt;gtz&lt;&lt;&quot; Tag &quot; &lt;&lt;tz&lt;&lt;&quot; Monat &quot;&lt;&lt;mo&lt;&lt; &quot; \n&quot;; 
                    } 
                    cout&lt;&lt;&quot;Monatende  \n  \n&quot;; 
                }    
                if (mo==2&amp;&amp;kjz==4) 
                { 
                    for(int tz=1; tz&lt;30; tz=tz+1)//Tageszählerschleife für 29 Tage Schaltjahr 
                    { 
                        gtz=gtz+1; 
                        int Tag=Tag+1; 
                        cout&lt;&lt;&quot;TN = &quot;&lt;&lt;gtz&lt;&lt;&quot; Tag &quot; &lt;&lt;tz&lt;&lt;&quot; Monat &quot;&lt;&lt;mo&lt;&lt; &quot; \n&quot;; 
                    } 
                    cout&lt;&lt;&quot;Februar  \n  \n&quot;; 
                } 
                else 
                { 
                    for(int tz=1; tz&lt;29; tz=tz+1)//Tageszählerschleife für 28 Tage NichtSchaltjahr 
                    { 
                        gtz=gtz+1; 
                        int Tag=Tag+1; 
                        cout&lt;&lt;&quot;TN = &quot;&lt;&lt;gtz&lt;&lt;&quot; Tag &quot; &lt;&lt;tz&lt;&lt;&quot; Monat &quot;&lt;&lt;mo&lt;&lt; &quot; \n&quot;; 
                    } 
                    cout&lt;&lt;&quot;Februar  \n  \n&quot;; 
                }    
            } 

        } 
        cout&lt;&lt;&quot;JAHRESENDE JAHR = &quot; &lt;&lt;kjz&lt;&lt; &quot;\n  \n&quot;; 
    } 
}
</code></pre>
<pre><code class="language-cpp">if (mo==4||mo==6||mo==9||mo==11) 
{ 
}    
if (mo==2&amp;&amp;kjz==4) 
{                    
} 
else
{
}
</code></pre>
<p>Na? Was denkst du?<br />
if( mo==2 &amp;&amp; kjz==4) startet eine neues if! Das hat mit dem ersten nichts zu tun! Wenn du dann in den else-Zweig springst, ist auch die erste (mit den 30-Tage-Monaten) wieder true.</p>
<p>Im übrigen hast du wahnsinnig viel Code-Duplizierungen. Solltest dir überlegen ob das nicht einfacher geht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1855823</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1855823</guid><dc:creator><![CDATA[l&#x27;abra d&#x27;or__]]></dc:creator><pubDate>Mon, 15 Feb 2010 10:59:53 GMT</pubDate></item><item><title><![CDATA[Reply to Unbekannter Fehler (Schaltjahreszählung) on Mon, 15 Feb 2010 11:01:59 GMT]]></title><description><![CDATA[<p>Du solltest dir überlegen, ob es nicht sinnvoller wäre, Variablennamen zu wählen, die man ohne den Kommentar bei der Definition versteht, auch wenn diese dann mal mehr als drei Buchstaben haben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1855829</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1855829</guid><dc:creator><![CDATA[Michael E.]]></dc:creator><pubDate>Mon, 15 Feb 2010 11:01:59 GMT</pubDate></item><item><title><![CDATA[Reply to Unbekannter Fehler (Schaltjahreszählung) on Mon, 15 Feb 2010 11:06:56 GMT]]></title><description><![CDATA[<p>Danke, jetzt funktioniert es. Bin leider blutiger Anfänger. Wie kann man denn die Duplizierungen kürzen?</p>
<p>Ich habe übrigens nur das Els mit</p>
<pre><code>if (mo==2&amp;&amp;kjz&lt;4)
</code></pre>
<p>ausgerüstet.</p>
<p>Übrigens macht Programmieren Spaß.... wenn es flutscht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1855830</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1855830</guid><dc:creator><![CDATA[Bekell]]></dc:creator><pubDate>Mon, 15 Feb 2010 11:06:56 GMT</pubDate></item><item><title><![CDATA[Reply to Unbekannter Fehler (Schaltjahreszählung) on Mon, 15 Feb 2010 11:16:44 GMT]]></title><description><![CDATA[<p>Quelltext wird durch die Verwendung von Funktionen übersichtlicher und verhindert Code Duplizierungen. Du solltest über die Verwendung einer Funktion nachdenken, die überprüft, ob ein Jahr ein Schaltjahr ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1855841</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1855841</guid><dc:creator><![CDATA[DocShoe]]></dc:creator><pubDate>Mon, 15 Feb 2010 11:16:44 GMT</pubDate></item><item><title><![CDATA[Reply to Unbekannter Fehler (Schaltjahreszählung) on Mon, 15 Feb 2010 11:41:30 GMT]]></title><description><![CDATA[<p>Was denkst du - ist 2100 ein Schaltjahr?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1855854</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1855854</guid><dc:creator><![CDATA[f.-th.]]></dc:creator><pubDate>Mon, 15 Feb 2010 11:41:30 GMT</pubDate></item><item><title><![CDATA[Reply to Unbekannter Fehler (Schaltjahreszählung) on Mon, 15 Feb 2010 11:52:00 GMT]]></title><description><![CDATA[<p>Also ich könnte mir so eine Funktion vorstellen, die den cout-Befehl auslagert, dann muß ich ihn nicht immer in allen Schleifen verändern.</p>
<pre><code>int Print(int, int); //Deklaration der Funktion

    for ()// Schleife
    {
     Ich weiß nicht, wie ich den Befehl hier aufrufe!
    }

    int Print() //Definition einer Funktion
    {
      cout&lt;&lt;&quot;TN = &quot;&lt;&lt;gtz&lt;&lt;&quot; TT &quot;&lt;&lt;gtz%7&lt;&lt;&quot; WN &quot;&lt;&lt;1+gtz/7&lt;&lt;&quot; Tag &quot; &lt;&lt;tz&lt;&lt;&quot; Monat &quot;&lt;&lt;mo&lt;&lt; &quot; \n&quot;;    
     }
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1855860</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1855860</guid><dc:creator><![CDATA[Bekell]]></dc:creator><pubDate>Mon, 15 Feb 2010 11:52:00 GMT</pubDate></item></channel></rss>