<?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[bool isInRange(int zahl, int untereGrenze, int obereGrenze);]]></title><description><![CDATA[<p>Hallooo</p>
<p>Ich bin jetzt seit einer Woche C++ am programmieren und mir selber Aufgaben gemacht und zum Teil aus Büchern und Internet.<br />
Mein Programm die ihr hier unten sieht ist eigentlich nichts besonderes.<br />
ich habe eine untere und eine obere Grenze (Zahlen bereich) wenn die Zahl die man eingibt im oberen oder unteren zahlenbereich ist dann geht es weiter und dann wird noch überprüft ob die Zahl gerade oder ungerade ist. mehr nicht. wie ihr sieht etwas ganz simples abr nicht einfach für einer der erst seit 1 woche programmiert.</p>
<p>zu meiner Frage:</p>
<p>Ich möchte eine Funktion implementieren, die sowohl den negativen als auch den positiven bereich überprüfen kann.</p>
<p>Habe mir vorgenommen das man maximal ein mal &quot;if - else&quot; verwendet kann.<br />
if (...)<br />
{ ...<br />
}<br />
else<br />
{ ...<br />
}</p>
<p>prototyp:<br />
bool isInRange(int zahl, int untereGrenze, int obereGrenze);</p>
<p>ist das überhaupt möglich? bin schon seit einer Zeit am hirnen und im Internet am schauen (bücher sollten kommen habe ich bestellt) aber komme nicht drauf.<br />
Ich sehe es schon vor mir muss sicher nur eine kleine Änderung machen aber schaffe es nicht.</p>
<p>kann mir jemand dabei helfen?</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;cmath&gt;

#define ERR_UNGERADE &quot;Die Zahl ist ungerade&quot;
#define ERR_GRENZE  &quot;Die Zahl ist ausserhalb der Grenze&quot;

#define OBEREGRENZE (100)
#define UNTEREGRENZE (50)

#define TEST 1

#define DEBUG 1
using namespace std;

//Funktionprototypen
bool insideRange (int zahl,int unten, int oben);
bool isEven (int zahl);

int main()
{	//Check bounds.
	if(UNTEREGRENZE&gt;OBEREGRENZE)
	{
		cout&lt;&lt; &quot;Falsche Konfiguration&quot;&lt;&lt; endl;
		return EXIT_FAILURE;
	}
#if TEST==1
	cout &lt;&lt; &quot;Testfunktion: &quot;&lt;&lt;boolalpha &lt;&lt;  insideRange(50, 0, 100)  &lt;&lt; endl;
	cout &lt;&lt; &quot;Testfunktion: &quot;&lt;&lt;boolalpha &lt;&lt;  insideRange(5, 90, 100)  &lt;&lt; endl;
	cout &lt;&lt; &quot;Testfunktion: &quot;&lt;&lt;boolalpha &lt;&lt; isEven(80)&lt;&lt; endl;
	cout &lt;&lt; &quot;Testfunktion: &quot;&lt;&lt;boolalpha &lt;&lt; isEven(85)&lt;&lt; endl;

#endif

	int zahl = 1;
#if DEBUG == 1
	cout &lt;&lt; &quot;zahl: &quot;&lt;&lt; zahl &lt;&lt; endl;
#endif

	cout &lt;&lt; &quot;bitte eingeben: &quot; &lt;&lt; endl;
	cin &gt;&gt; zahl; 
	cout &lt;&lt; &quot;zahl: &quot;&lt;&lt; zahl &lt;&lt; endl;

	int error = 0;

		if (insideRange(zahl, UNTEREGRENZE, OBEREGRENZE) )
		{
			cout &lt;&lt; &quot;Oberegrenze: &quot;  &lt;&lt; endl;
		}
		else if (insideRange(zahl, -OBEREGRENZE, -UNTEREGRENZE) )
		{
			cout &lt;&lt; &quot;Unteregrenze: &quot;  &lt;&lt; endl;
		}
		else
		{   
			error+=1; 
		}

		if (!error)
		{
			if(isEven(zahl))
			{
				cout &lt;&lt; &quot;Zahl ist gerade&quot; &lt;&lt; endl;
			}
			else
			{
				error+=1; //Fall 1: Zahl ist ungerade
			}
		}
		switch (error)
		{
		case 0:
			cout &lt;&lt; &quot;Zahl ist gerade&quot; &lt;&lt; endl;
			break;
		case 1:
			cout &lt;&lt; &quot;Ist ein Fehler aufgetreten&quot; &lt;&lt; endl;

			break;
		default:
			break;
		}

		return (error&gt;0 ? EXIT_FAILURE : EXIT_SUCCESS);
}

bool insideRange (int zahl,int unten, int oben)
{
	if (zahl&gt;= unten &amp;&amp; zahl&lt;= oben)
	{
		return true;
	}
	else
	{
		return false;
	}
}

bool isEven(int zahl)
{	
	if (!(zahl%2))
	{
		return true;
	}
	else
	{
		return false;
	}

}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/246027/bool-isinrange-int-zahl-int-unteregrenze-int-oberegrenze</link><generator>RSS for Node</generator><lastBuildDate>Fri, 18 Sep 2026 01:51:31 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/246027.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 22 Jul 2009 08:46:04 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to bool isInRange(int zahl, int untereGrenze, int obereGrenze); on Wed, 22 Jul 2009 08:46:04 GMT]]></title><description><![CDATA[<p>Hallooo</p>
<p>Ich bin jetzt seit einer Woche C++ am programmieren und mir selber Aufgaben gemacht und zum Teil aus Büchern und Internet.<br />
Mein Programm die ihr hier unten sieht ist eigentlich nichts besonderes.<br />
ich habe eine untere und eine obere Grenze (Zahlen bereich) wenn die Zahl die man eingibt im oberen oder unteren zahlenbereich ist dann geht es weiter und dann wird noch überprüft ob die Zahl gerade oder ungerade ist. mehr nicht. wie ihr sieht etwas ganz simples abr nicht einfach für einer der erst seit 1 woche programmiert.</p>
<p>zu meiner Frage:</p>
<p>Ich möchte eine Funktion implementieren, die sowohl den negativen als auch den positiven bereich überprüfen kann.</p>
<p>Habe mir vorgenommen das man maximal ein mal &quot;if - else&quot; verwendet kann.<br />
if (...)<br />
{ ...<br />
}<br />
else<br />
{ ...<br />
}</p>
<p>prototyp:<br />
bool isInRange(int zahl, int untereGrenze, int obereGrenze);</p>
<p>ist das überhaupt möglich? bin schon seit einer Zeit am hirnen und im Internet am schauen (bücher sollten kommen habe ich bestellt) aber komme nicht drauf.<br />
Ich sehe es schon vor mir muss sicher nur eine kleine Änderung machen aber schaffe es nicht.</p>
<p>kann mir jemand dabei helfen?</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;cmath&gt;

#define ERR_UNGERADE &quot;Die Zahl ist ungerade&quot;
#define ERR_GRENZE  &quot;Die Zahl ist ausserhalb der Grenze&quot;

#define OBEREGRENZE (100)
#define UNTEREGRENZE (50)

#define TEST 1

#define DEBUG 1
using namespace std;

//Funktionprototypen
bool insideRange (int zahl,int unten, int oben);
bool isEven (int zahl);

int main()
{	//Check bounds.
	if(UNTEREGRENZE&gt;OBEREGRENZE)
	{
		cout&lt;&lt; &quot;Falsche Konfiguration&quot;&lt;&lt; endl;
		return EXIT_FAILURE;
	}
#if TEST==1
	cout &lt;&lt; &quot;Testfunktion: &quot;&lt;&lt;boolalpha &lt;&lt;  insideRange(50, 0, 100)  &lt;&lt; endl;
	cout &lt;&lt; &quot;Testfunktion: &quot;&lt;&lt;boolalpha &lt;&lt;  insideRange(5, 90, 100)  &lt;&lt; endl;
	cout &lt;&lt; &quot;Testfunktion: &quot;&lt;&lt;boolalpha &lt;&lt; isEven(80)&lt;&lt; endl;
	cout &lt;&lt; &quot;Testfunktion: &quot;&lt;&lt;boolalpha &lt;&lt; isEven(85)&lt;&lt; endl;

#endif

	int zahl = 1;
#if DEBUG == 1
	cout &lt;&lt; &quot;zahl: &quot;&lt;&lt; zahl &lt;&lt; endl;
#endif

	cout &lt;&lt; &quot;bitte eingeben: &quot; &lt;&lt; endl;
	cin &gt;&gt; zahl; 
	cout &lt;&lt; &quot;zahl: &quot;&lt;&lt; zahl &lt;&lt; endl;

	int error = 0;

		if (insideRange(zahl, UNTEREGRENZE, OBEREGRENZE) )
		{
			cout &lt;&lt; &quot;Oberegrenze: &quot;  &lt;&lt; endl;
		}
		else if (insideRange(zahl, -OBEREGRENZE, -UNTEREGRENZE) )
		{
			cout &lt;&lt; &quot;Unteregrenze: &quot;  &lt;&lt; endl;
		}
		else
		{   
			error+=1; 
		}

		if (!error)
		{
			if(isEven(zahl))
			{
				cout &lt;&lt; &quot;Zahl ist gerade&quot; &lt;&lt; endl;
			}
			else
			{
				error+=1; //Fall 1: Zahl ist ungerade
			}
		}
		switch (error)
		{
		case 0:
			cout &lt;&lt; &quot;Zahl ist gerade&quot; &lt;&lt; endl;
			break;
		case 1:
			cout &lt;&lt; &quot;Ist ein Fehler aufgetreten&quot; &lt;&lt; endl;

			break;
		default:
			break;
		}

		return (error&gt;0 ? EXIT_FAILURE : EXIT_SUCCESS);
}

bool insideRange (int zahl,int unten, int oben)
{
	if (zahl&gt;= unten &amp;&amp; zahl&lt;= oben)
	{
		return true;
	}
	else
	{
		return false;
	}
}

bool isEven(int zahl)
{	
	if (!(zahl%2))
	{
		return true;
	}
	else
	{
		return false;
	}

}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1747382</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1747382</guid><dc:creator><![CDATA[whaaatz]]></dc:creator><pubDate>Wed, 22 Jul 2009 08:46:04 GMT</pubDate></item><item><title><![CDATA[Reply to bool isInRange(int zahl, int untereGrenze, int obereGrenze); on Wed, 22 Jul 2009 08:56:52 GMT]]></title><description><![CDATA[<p>1.) Ich würde das nicht unbedingt als &quot;Projekt&quot; betrachten. Wäre im C++-Forum wohl besser aufgehoben.</p>
<p>2.) Solltest dir mal das logische ODER anschauen:</p>
<pre><code class="language-cpp">if (insideRange(zahl, UNTEREGRENZE, OBEREGRENZE) || insideRange(zahl, -OBEREGRENZE, -UNTEREGRENZE)) {
...
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1747392</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1747392</guid><dc:creator><![CDATA[Dasd]]></dc:creator><pubDate>Wed, 22 Jul 2009 08:56:52 GMT</pubDate></item><item><title><![CDATA[Reply to bool isInRange(int zahl, int untereGrenze, int obereGrenze); on Wed, 22 Jul 2009 09:06:35 GMT]]></title><description><![CDATA[<p>whaaatz schrieb:</p>
<blockquote>
<pre><code>bool insideRange (int zahl,int unten, int oben)
</code></pre>
</blockquote>
<p>?</p>
<pre><code>bool insideRange (int unten,int zahl,int oben)
</code></pre>
<p>!<br />
Weil es schon seit mindestens dem BC3.1 die range-Funktion mit dieser Schnittstelle gibt. Wenn Du Dich jetzt an eine andere Reihenfolge gewöhnst, kommst Du irgendwann in Teufels Küche, befürchte ich.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1747402</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1747402</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Wed, 22 Jul 2009 09:06:35 GMT</pubDate></item><item><title><![CDATA[Reply to bool isInRange(int zahl, int untereGrenze, int obereGrenze); on Wed, 22 Jul 2009 09:20:41 GMT]]></title><description><![CDATA[<p>whaaatz schrieb:</p>
<blockquote>
<p>Ich bin jetzt seit einer Woche C++ am programmieren und mir selber Aufgaben gemacht und zum Teil aus Büchern und Internet.</p>
</blockquote>
<p>Aber der Stil ist schrecklich. Lösch die Bücher am besten sofort.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;cmath&gt;
//Bis hier war's ok

#define ERR_UNGERADE &quot;Die Zahl ist ungerade&quot;
#define ERR_GRENZE  &quot;Die Zahl ist ausserhalb der Grenze&quot;
//KEINE MAKROS NEHMEN!

#define OBEREGRENZE (100)
#define UNTEREGRENZE (50)
//KEINE MAKROS NEHMEN! Wozu die nutzlosen Klammern?

#define TEST 1
//Mach das unten und ohne Makro

#define DEBUG 1
//Mach das unten und ohne Makro

using namespace std;
//Eine Zeile ok

bool insideRange (int zahl,int unten, int oben);
bool isEven (int zahl);
//Funktionprototypen völlig sinnlos

int main()
{
	if(UNTEREGRENZE&gt;OBEREGRENZE)
	{
		cout&lt;&lt; &quot;Falsche Konfiguration&quot;&lt;&lt; endl;
		return EXIT_FAILURE;
	}
	//Test eher sinnloc

#if TEST==1
	cout &lt;&lt; &quot;Testfunktion: &quot;&lt;&lt;boolalpha &lt;&lt;  insideRange(50, 0, 100)  &lt;&lt; endl;
	cout &lt;&lt; &quot;Testfunktion: &quot;&lt;&lt;boolalpha &lt;&lt;  insideRange(5, 90, 100)  &lt;&lt; endl;
	cout &lt;&lt; &quot;Testfunktion: &quot;&lt;&lt;boolalpha &lt;&lt; isEven(80)&lt;&lt; endl;
	cout &lt;&lt; &quot;Testfunktion: &quot;&lt;&lt;boolalpha &lt;&lt; isEven(85)&lt;&lt; endl;
#endif
//Ganz schlecht. Besser wäre zum Beispiel
//#define TEST(x) cout&lt;&lt;#x&lt;&lt;'='&lt;&lt;(x)&lt;&lt;'\n'
//TEST(insideRange(50,0,100);
//TEST(insideRange(50,90,100);
//...

	int zahl = 1;
#if DEBUG == 1
	cout &lt;&lt; &quot;zahl: &quot;&lt;&lt; zahl &lt;&lt; endl;
#endif
//Willste mich veralbern?

	cout &lt;&lt; &quot;bitte eingeben: &quot; &lt;&lt; endl;
	cin &gt;&gt; zahl; 
	cout &lt;&lt; &quot;zahl: &quot;&lt;&lt; zahl &lt;&lt; endl;
//Wozu die Ausgabe?

	int error = 0;

		if (insideRange(zahl, UNTEREGRENZE, OBEREGRENZE) )
		{
			cout &lt;&lt; &quot;Oberegrenze: &quot;  &lt;&lt; endl;
		}
		else if (insideRange(zahl, -OBEREGRENZE, -UNTEREGRENZE) )
		{
			cout &lt;&lt; &quot;Unteregrenze: &quot;  &lt;&lt; endl;
		}
//Hier ist völlig unklar, was berechnet wurde
		else
		{   
			error+=1; 
		}
//Bei Fehler rausreturnen, das künstliche Flag ist Pascal

		if (!error)
		{
			if(isEven(zahl))
			{
				cout &lt;&lt; &quot;Zahl ist gerade&quot; &lt;&lt; endl;
			}
			else
			{
				error+=1; //Fall 1: Zahl ist ungerade
//Hä?
			}
		}
		switch (error)
		{
		case 0:
			cout &lt;&lt; &quot;Zahl ist gerade&quot; &lt;&lt; endl;
			break;
		case 1:
			cout &lt;&lt; &quot;Ist ein Fehler aufgetreten&quot; &lt;&lt; endl;

			break;
		default:
			break;
		}
//Jetzt ein switch, wo ein if sein soll
		return (error&gt;0 ? EXIT_FAILURE : EXIT_SUCCESS);
//Nutzlose Klammern, return IST KEINE FUNKTION, 
//Wozu in aller Welt ?: nehmen? Hättest bei Fehlern einfach 
//direkt EXIT_FAILURE rausreturnen sollen. 
}

bool insideRange (int zahl,int unten, int oben)
{
	if (zahl&gt;= unten &amp;&amp; zahl&lt;= oben)
	{
		return true;
	}
	else
	{
		return false;
	}
}

bool isEven(int zahl)
{	
	if (!(zahl%2))
//Mach das ! dort weg! ! ist logisch. Du willst aber numerisch testen, 
//also if(zahl%2)==0)
	{
		return true;
	}
	else
	{
		return false;
	}
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1747411</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1747411</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Wed, 22 Jul 2009 09:20:41 GMT</pubDate></item><item><title><![CDATA[Reply to bool isInRange(int zahl, int untereGrenze, int obereGrenze); on Wed, 22 Jul 2009 10:10:07 GMT]]></title><description><![CDATA[<p>volkard schrieb:</p>
<blockquote>
<p>whaaatz schrieb:</p>
<blockquote>
<p>Ich bin jetzt seit einer Woche C++ am programmieren und mir selber Aufgaben gemacht und zum Teil aus Büchern und Internet.</p>
</blockquote>
<p>Aber der Stil ist schrecklich. Lösch die Bücher am besten sofort.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;cmath&gt;
//Bis hier war's ok

#define ERR_UNGERADE &quot;Die Zahl ist ungerade&quot;
#define ERR_GRENZE  &quot;Die Zahl ist ausserhalb der Grenze&quot;
//KEINE MAKROS NEHMEN!

#define OBEREGRENZE (100)
#define UNTEREGRENZE (50)
//KEINE MAKROS NEHMEN! Wozu die nutzlosen Klammern?

#define TEST 1
//Mach das unten und ohne Makro

#define DEBUG 1
//Mach das unten und ohne Makro

using namespace std;
//Eine Zeile ok

bool insideRange (int zahl,int unten, int oben);
bool isEven (int zahl);
//Funktionprototypen völlig sinnlos

int main()
{
	if(UNTEREGRENZE&gt;OBEREGRENZE)
	{
		cout&lt;&lt; &quot;Falsche Konfiguration&quot;&lt;&lt; endl;
		return EXIT_FAILURE;
	}
	//Test eher sinnloc
	
#if TEST==1
	cout &lt;&lt; &quot;Testfunktion: &quot;&lt;&lt;boolalpha &lt;&lt;  insideRange(50, 0, 100)  &lt;&lt; endl;
	cout &lt;&lt; &quot;Testfunktion: &quot;&lt;&lt;boolalpha &lt;&lt;  insideRange(5, 90, 100)  &lt;&lt; endl;
	cout &lt;&lt; &quot;Testfunktion: &quot;&lt;&lt;boolalpha &lt;&lt; isEven(80)&lt;&lt; endl;
	cout &lt;&lt; &quot;Testfunktion: &quot;&lt;&lt;boolalpha &lt;&lt; isEven(85)&lt;&lt; endl;
#endif
//Ganz schlecht. Besser wäre zum Beispiel
//#define TEST(x) cout&lt;&lt;#x&lt;&lt;'='&lt;&lt;(x)&lt;&lt;'\n'
//TEST(insideRange(50,0,100);
//TEST(insideRange(50,90,100);
//...

	int zahl = 1;
#if DEBUG == 1
	cout &lt;&lt; &quot;zahl: &quot;&lt;&lt; zahl &lt;&lt; endl;
#endif
//Willste mich veralbern?
	
	cout &lt;&lt; &quot;bitte eingeben: &quot; &lt;&lt; endl;
	cin &gt;&gt; zahl; 
	cout &lt;&lt; &quot;zahl: &quot;&lt;&lt; zahl &lt;&lt; endl;
//Wozu die Ausgabe?
	
	int error = 0;

		if (insideRange(zahl, UNTEREGRENZE, OBEREGRENZE) )
		{
			cout &lt;&lt; &quot;Oberegrenze: &quot;  &lt;&lt; endl;
		}
		else if (insideRange(zahl, -OBEREGRENZE, -UNTEREGRENZE) )
		{
			cout &lt;&lt; &quot;Unteregrenze: &quot;  &lt;&lt; endl;
		}
//Hier ist völlig unklar, was berechnet wurde
		else
		{   
			error+=1; 
		}
//Bei Fehler rausreturnen, das künstliche Flag ist Pascal
		
		if (!error)
		{
			if(isEven(zahl))
			{
				cout &lt;&lt; &quot;Zahl ist gerade&quot; &lt;&lt; endl;
			}
			else
			{
				error+=1; //Fall 1: Zahl ist ungerade
//Hä?
			}
		}
		switch (error)
		{
		case 0:
			cout &lt;&lt; &quot;Zahl ist gerade&quot; &lt;&lt; endl;
			break;
		case 1:
			cout &lt;&lt; &quot;Ist ein Fehler aufgetreten&quot; &lt;&lt; endl;
			
			break;
		default:
			break;
		}
//Jetzt ein switch, wo ein if sein soll
		return (error&gt;0 ? EXIT_FAILURE : EXIT_SUCCESS);
//Nutzlose Klammern, return IST KEINE FUNKTION, 
//Wozu in aller Welt ?: nehmen? Hättest bei Fehlern einfach 
//direkt EXIT_FAILURE rausreturnen sollen. 
}

bool insideRange (int zahl,int unten, int oben)
{
	if (zahl&gt;= unten &amp;&amp; zahl&lt;= oben)
	{
		return true;
	}
	else
	{
		return false;
	}
}

bool isEven(int zahl)
{	
	if (!(zahl%2))
//Mach das ! dort weg! ! ist logisch. Du willst aber numerisch testen, 
//also if(zahl%2)==0)
	{
		return true;
	}
	else
	{
		return false;
	}
}
</code></pre>
</blockquote>
<p>Ich weiss das viele unnützlich ist aber ich wollte nur so viel wie möglich in ein simples Programm linken damit ich besser üben kann...<br />
aber danke das du dir die mühe gemacht hast.... werde deine Kommentar sicherlich bei meiner nächsten Aufgaben berücksichtigen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1747441</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1747441</guid><dc:creator><![CDATA[whaaatz]]></dc:creator><pubDate>Wed, 22 Jul 2009 10:10:07 GMT</pubDate></item><item><title><![CDATA[Reply to bool isInRange(int zahl, int untereGrenze, int obereGrenze); on Thu, 23 Jul 2009 11:48:09 GMT]]></title><description><![CDATA[<p>Dieser Thread wurde von Moderator/in <a href="http://www.c-plusplus.net/forum/profile-var-mode-is-viewprofile-and-u-is-4180.html" rel="nofollow">Korbinian</a> aus dem Forum <a href="http://www.c-plusplus.net/forum/viewforum-var-f-is-11.html" rel="nofollow">Projekte</a> in das Forum <a href="http://www.c-plusplus.net/forum/viewforum-var-f-is-15.html" rel="nofollow">C++</a> verschoben.</p>
<p>Im Zweifelsfall bitte auch folgende Hinweise beachten:<br />
<a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-39405.html" rel="nofollow">C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?</a></p>
<p><em>Dieses Posting wurde automatisch erzeugt.</em></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1748162</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1748162</guid><dc:creator><![CDATA[C++ Forumbot]]></dc:creator><pubDate>Thu, 23 Jul 2009 11:48:09 GMT</pubDate></item><item><title><![CDATA[Reply to bool isInRange(int zahl, int untereGrenze, int obereGrenze); on Thu, 23 Jul 2009 14:00:54 GMT]]></title><description><![CDATA[<p>ich würds sorum machen:</p>
<pre><code class="language-cpp">bool isEven(int zahl) 
{    
    if (zahl%2)
    {
        return false;
    }
    else
    {
        return true;
    }
}
</code></pre>
<p>und mich dann fragen: warum englischer bezeichner und deutscher variablenname?<br />
und dann würd ichs einfach so machen:</p>
<pre><code class="language-cpp">bool isEven(int number)
{
  return number%2 == 0;
}
</code></pre>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1748285</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1748285</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Thu, 23 Jul 2009 14:00:54 GMT</pubDate></item><item><title><![CDATA[Reply to bool isInRange(int zahl, int untereGrenze, int obereGrenze); on Sat, 25 Jul 2009 02:24:58 GMT]]></title><description><![CDATA[<p>da volkard vergessen hat dir 'ne andere Möglichkeit zu zeigen, hole ich das mal nach</p>
<pre><code class="language-cpp">#define ERR_UNGERADE &quot;Die Zahl ist ungerade&quot; 
#define ERR_GRENZE  &quot;Die Zahl ist ausserhalb der Grenze&quot; 
//KEINE MAKROS NEHMEN! 

#define OBEREGRENZE (100) 
#define UNTEREGRENZE (50) 
//KEINE MAKROS NEHMEN! Wozu die nutzlosen Klammern?
</code></pre>
<pre><code class="language-cpp">const std::string ERR_UNGERADE = &quot;Die Zahl ist ungerade&quot;;
const std::string ERR_GRENZE = &quot;Die Zahl ist ausserhalb der Grenze&quot;;
const int OBEREGRENZE=100;
const int UNTEREGRENZE=50;
</code></pre>
<p>1. wegen der Typensicherheit<br />
2. die Variablen können nicht mal ebent durch unachtsam magisch verändert werden.</p>
<p>Predeklarationen sind nur bei soetwas notwendig (oder wenn der Compiler jammert):</p>
<pre><code class="language-cpp">void foo();
void bar(){foo();}
void foo(){bar();}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1749227</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1749227</guid><dc:creator><![CDATA[kung]]></dc:creator><pubDate>Sat, 25 Jul 2009 02:24:58 GMT</pubDate></item><item><title><![CDATA[Reply to bool isInRange(int zahl, int untereGrenze, int obereGrenze); on Sat, 25 Jul 2009 09:27:12 GMT]]></title><description><![CDATA[<p>Makros haben auch oft die Probleme, die die dumme Textersetzung mit sich bringt (bei einfachen Konstanen vielleicht weniger). Aber es fehlen zum Beispiel auch Debugsymbole.</p>
<p>Ich würde dennoch <code>const char*</code> statt <code>const std::string nehmen</code> , dieser ist nämlich für Stringliterale stark übertrieben.</p>
<pre><code class="language-cpp">const char* ERR_UNGERADE = &quot;Die Zahl ist ungerade&quot;;
const char* ERR_GRENZE = &quot;Die Zahl ist ausserhalb der Grenze&quot;;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1749296</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1749296</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Sat, 25 Jul 2009 09:27:12 GMT</pubDate></item><item><title><![CDATA[Reply to bool isInRange(int zahl, int untereGrenze, int obereGrenze); on Tue, 28 Jul 2009 15:42:51 GMT]]></title><description><![CDATA[<p>Nexus schrieb:</p>
<blockquote>
<p>Ich würde dennoch <code>const char*</code> statt <code>const std::string nehmen</code> , dieser ist nämlich für Stringliterale stark übertrieben.</p>
</blockquote>
<p>Hahahahahahahaha ....</p>
<p>Wir wollten ihm doch modernes C++ beibringen. Da nimmt man den std::string!<br />
Genauso wie man std::cout verwendet statt printf.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1751033</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1751033</guid><dc:creator><![CDATA[nurf]]></dc:creator><pubDate>Tue, 28 Jul 2009 15:42:51 GMT</pubDate></item><item><title><![CDATA[Reply to bool isInRange(int zahl, int untereGrenze, int obereGrenze); on Tue, 28 Jul 2009 18:34:29 GMT]]></title><description><![CDATA[<p>nurf schrieb:</p>
<blockquote>
<p>Hahahahahahahaha ....</p>
<p>Wir wollten ihm doch modernes C++ beibringen. Da nimmt man den std::string!<br />
Genauso wie man std::cout verwendet statt printf.</p>
</blockquote>
<p>Schade, dass du keine Argumente hast, aber zu den Leuten gehörst, die C++-Mittel prinzipiell besser finden, egal um welches Problem es geht.</p>
<p>Sieh es ein, es gibt an dieser Stelle keinen Grund für <code>std::string</code> , aber eine Menge Gründe dagegen. Benutzt du auch kein <code>&lt;cmath&gt;</code> , weil es das in C schon gab? <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/1751112</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1751112</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Tue, 28 Jul 2009 18:34:29 GMT</pubDate></item><item><title><![CDATA[Reply to bool isInRange(int zahl, int untereGrenze, int obereGrenze); on Tue, 28 Jul 2009 18:47:47 GMT]]></title><description><![CDATA[<p>Als Pendant zu <code>const std::string</code> würde ich hier <code>const char* const</code> (statt <code>const char*</code> ) nehmen, wegen unveränderbar und so. Und std::string hat hier auch Vorteile, z.B. string.length, rbegin/rend, die find-Methoden usw. Muss man natürlich schauen, wenn man's nicht braucht (was ja meistens der Fall ist), reicht auch der Zeiger.<br />
Oh, und vorteilhaft ist es auch bei der Übergabe an Funktionen, die <code>const std::string&amp;</code> nehmen, damit nicht jedesmal eine Kopie erzeugt wird.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1751123</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1751123</guid><dc:creator><![CDATA[Badestrand]]></dc:creator><pubDate>Tue, 28 Jul 2009 18:47:47 GMT</pubDate></item><item><title><![CDATA[Reply to bool isInRange(int zahl, int untereGrenze, int obereGrenze); on Tue, 28 Jul 2009 18:51:58 GMT]]></title><description><![CDATA[<p>Nexus schrieb:</p>
<blockquote>
<p>Sieh es ein, es gibt an dieser Stelle keinen Grund für <code>std::string</code> , aber eine Menge Gründe dagegen. Benutzt du auch kein <code>&lt;cmath&gt;</code> , weil es das in C schon gab? <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>
</blockquote>
<p>Ja dann mal her mit den Gründen, scheint mir eher tief verwurzelter Aberglaube zu sein.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1751128</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1751128</guid><dc:creator><![CDATA[nurf]]></dc:creator><pubDate>Tue, 28 Jul 2009 18:51:58 GMT</pubDate></item><item><title><![CDATA[Reply to bool isInRange(int zahl, int untereGrenze, int obereGrenze); on Tue, 28 Jul 2009 19:02:29 GMT]]></title><description><![CDATA[<p>nurf schrieb:</p>
<blockquote>
<p>Nexus schrieb:</p>
<blockquote>
<p>Sieh es ein, es gibt an dieser Stelle keinen Grund für <code>std::string</code> , aber eine Menge Gründe dagegen. Benutzt du auch kein <code>&lt;cmath&gt;</code> , weil es das in C schon gab? <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>
</blockquote>
<p>Ja dann mal her mit den Gründen, scheint mir eher tief verwurzelter Aberglaube zu sein.</p>
</blockquote>
<p>Hmm, das ist ne fixe Meldung, du wirst die jetzt nicht nach irgendwlchen Zeichen durchsuchen wollen, oder sonst was damit anstellen, wofür du die ganze Macht der string-Klasse benötigst. Du willst einfach einen unveränderlichen Text, dafür ist das minimale Mittel ein &quot;const char*&quot;. Deshalb spricht einiges dafür. Und das sollte auch reichen.</p>
<p>Oder hast du jetzt deine &quot;Aussage&quot; auf den Teil mit cmath bezogen? Ich hoffe zutiefst dass du einfach zu faul warst den quote zu bearbeiten...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1751137</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1751137</guid><dc:creator><![CDATA[meck0r0r]]></dc:creator><pubDate>Tue, 28 Jul 2009 19:02:29 GMT</pubDate></item><item><title><![CDATA[Reply to bool isInRange(int zahl, int untereGrenze, int obereGrenze); on Tue, 28 Jul 2009 19:06:45 GMT]]></title><description><![CDATA[<p>@ Badestrand:<br />
Hm ja. <code>std::string</code> hat schon an manchen Orten Vorteile, aber ihn grundsätzlich immer zu empfehlen, nur weil er C++ ist, finde ich nicht gut.</p>
<p>Schlimm finde ich sowas:</p>
<pre><code class="language-cpp">void MyClass::OpenFile(const std::string&amp; FileName)
{
    FileStream.open(FileName.c_str());
}

int main()
{
    MyClass x;
    x.OpenFile(&quot;file.txt&quot;);
}
</code></pre>
<p>Je nachdem wäre es sogar eine Überlegung wert, eine eigene Klasse für solche unveränderlichen Strings zu erstellen. Geht zwar auch ohne, aber wenns um Optimierung geht, könnte sowas schon praktisch sein.</p>
<p>nurf schrieb:</p>
<blockquote>
<p>Ja dann mal her mit den Gründen, scheint mir eher tief verwurzelter Aberglaube zu sein.</p>
</blockquote>
<p>Okay, da du scheinbar immer noch keine Argumente dafür hast: Du brauchst die String-Funktionalität in vielen Fällen gar nicht! Ein <code>std::string</code> hat eine dynamische Speicherverwaltung, Wachstumssemantik mit Grösse und Kapazität, oft auch gespeicherte Iteratoren, also einen rechten Overhead. <code>sizeof(std::string)</code> ist bei mir im Release-Modus 28, das ist nicht selten mehr als überhaupt als Text gespeichert wird (in Anwendungsfällen von Stringliteralen).</p>
<p>Natürlich kann man sich auch grundsätzlich nicht um solche Überlegungen kümmern und alles als Premature Optimization abtun. Am besten dabei ständig nach dem Dogma &quot;C ist grundsätzlich schlecht, man muss in jedem Fall C++ nutzen&quot; handeln und gleichzeitig anderen Aberglaube unterstellen. Naja... <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/1751138</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1751138</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Tue, 28 Jul 2009 19:06:45 GMT</pubDate></item><item><title><![CDATA[Reply to bool isInRange(int zahl, int untereGrenze, int obereGrenze); on Tue, 28 Jul 2009 21:57:44 GMT]]></title><description><![CDATA[<p>C++ Strings sind grundsätzlich &quot;broken&quot;. Man sollte sie trotzdem vielerorts verwenden, weil sie halt Standard sind, und ein schlechter Standard immer noch besser ist als 100 String-Klassen von 100 Libraries in einem Projekt (*kotz*).</p>
<p>Für Fehlermeldungs-Konstanten finde ich std::string aber auch nicht gerade &quot;nötig&quot;.</p>
<p><code>const char* const</code> hat sogar einen wichtigen Vorteil, wenn es um statische String Konstanten geht: es benötigt keine Konstruktoren -&gt; kein &quot;static initialization order fiasco&quot;.</p>
<p>nurf schrieb:</p>
<blockquote>
<p>Hahahahahahahaha ....</p>
<p>Wir wollten ihm doch modernes C++ beibringen. Da nimmt man den std::string!<br />
Genauso wie man std::cout verwendet statt printf.</p>
</blockquote>
<p>Lachst du dich hier selbst aus, weil du weisst was du gleich für Unsinn ablassen wirst? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1751235</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1751235</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Tue, 28 Jul 2009 21:57:44 GMT</pubDate></item></channel></rss>