<?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[Komisches Ergebnis einer Rechnung mit float]]></title><description><![CDATA[<p>Ich hab mal aus fun einen Rechner zum berechnen von der Fläche und vom Umfang eines Kreises. Das Problem ist dass ich für Pi float genommen habe und da float ja nicht genug stellen für viele Pi stellen hat und deshalb ein Ergebnis wie dieses hergibt: 3.53282e-038<br />
das problem ist, als ich dann zum test für Pi einfach 3 genommen habe, hat er genausoein Ergebnis rausgeworfen.<br />
3.53282e-038 kommt raus wenn Pi 3 ist und der Radius auch 3. 2*3*3=18 hätte ich erwartet aber ich schätze mal es liegt daran dass ich float falsch verwende.<br />
welchen typ sollte ich benutzen bzw. wie float? Ich will nen klares Ergebnis</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/304796/komisches-ergebnis-einer-rechnung-mit-float</link><generator>RSS for Node</generator><lastBuildDate>Sat, 27 Jun 2026 00:00:43 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/304796.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 14 Jun 2012 12:58:58 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Komisches Ergebnis einer Rechnung mit float on Thu, 14 Jun 2012 12:58:58 GMT]]></title><description><![CDATA[<p>Ich hab mal aus fun einen Rechner zum berechnen von der Fläche und vom Umfang eines Kreises. Das Problem ist dass ich für Pi float genommen habe und da float ja nicht genug stellen für viele Pi stellen hat und deshalb ein Ergebnis wie dieses hergibt: 3.53282e-038<br />
das problem ist, als ich dann zum test für Pi einfach 3 genommen habe, hat er genausoein Ergebnis rausgeworfen.<br />
3.53282e-038 kommt raus wenn Pi 3 ist und der Radius auch 3. 2*3*3=18 hätte ich erwartet aber ich schätze mal es liegt daran dass ich float falsch verwende.<br />
welchen typ sollte ich benutzen bzw. wie float? Ich will nen klares Ergebnis</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2223113</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2223113</guid><dc:creator><![CDATA[Golol]]></dc:creator><pubDate>Thu, 14 Jun 2012 12:58:58 GMT</pubDate></item><item><title><![CDATA[Reply to Komisches Ergebnis einer Rechnung mit float on Thu, 14 Jun 2012 13:06:02 GMT]]></title><description><![CDATA[<p>Zeig mal den Code.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2223118</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2223118</guid><dc:creator><![CDATA[IrgendeinName]]></dc:creator><pubDate>Thu, 14 Jun 2012 13:06:02 GMT</pubDate></item><item><title><![CDATA[Reply to Komisches Ergebnis einer Rechnung mit float on Thu, 14 Jun 2012 13:06:56 GMT]]></title><description><![CDATA[<p>Zeig doch mal deine Rechnung. float ist schon ziemlich genau, du hast bestimmt irgendeine Dummheit gemacht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2223121</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2223121</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Thu, 14 Jun 2012 13:06:56 GMT</pubDate></item><item><title><![CDATA[Reply to Komisches Ergebnis einer Rechnung mit float on Thu, 14 Jun 2012 13:20:27 GMT]]></title><description><![CDATA[<pre><code>int main ()
{
	float u;			//Deklarierungen
	float r;
	float f;
	float P;
	int a;				//a für Auswahl

	P = 3;		//Definierung Pi
	u = 2 * r * P;
	f = r * r * P;

	cout &lt;&lt; &quot;Was wollen sie berechnen?&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;1: Umfang&quot; &lt;&lt; endl &lt;&lt; &quot;2: Fläche&quot; &lt;&lt; endl;
	cin &gt;&gt; a;

	if (a == 1)
	{
		cout &lt;&lt; &quot;Sie haben Umfang gewählt.&quot; &lt;&lt; endl;
		cout &lt;&lt; &quot;Geben sie den Radius ein:&quot; &lt;&lt; endl;
		cin &gt;&gt; r;
		cout &lt;&lt; &quot;Der Umfang beträgt:&quot; &lt;&lt; u &lt;&lt; endl;
	}
	return 0;

}
</code></pre>
<p>das zweite if für die Fläche hab ich nochnet weil ich erstmal testen woltle ob umfang richtig ist</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2223130</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2223130</guid><dc:creator><![CDATA[Golol]]></dc:creator><pubDate>Thu, 14 Jun 2012 13:20:27 GMT</pubDate></item><item><title><![CDATA[Reply to Komisches Ergebnis einer Rechnung mit float on Thu, 14 Jun 2012 13:25:28 GMT]]></title><description><![CDATA[<p>Du musst die Berechnung für u hinter den Input, in die if-Abfrage tun.<br />
Du dafst niemals unitialisierte Variablen verwenden!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2223133</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2223133</guid><dc:creator><![CDATA[IrgendeinName]]></dc:creator><pubDate>Thu, 14 Jun 2012 13:25:28 GMT</pubDate></item><item><title><![CDATA[Reply to Komisches Ergebnis einer Rechnung mit float on Thu, 14 Jun 2012 13:26:43 GMT]]></title><description><![CDATA[<p>C++ hat keine lazy-evaluation. In Zeile 10 und 11 wird das Ergebnis mit dem zu der Zeit geltenden Werten berechnet. Dort definierst du <strong>keine</strong> Rechenvorschrift, wie später u und f zu berechnen sind. Da r an der Stelle aber irgendeinen Unsinnswert hat, kommt auch ein Unsinnsergebnis für u und f heraus. Dieses ändert sich auch nicht, wenn du später r veränderst.</p>
<p>Suchst du vielleicht Funktionen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2223134</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2223134</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Thu, 14 Jun 2012 13:26:43 GMT</pubDate></item><item><title><![CDATA[Reply to Komisches Ergebnis einer Rechnung mit float on Thu, 14 Jun 2012 13:34:16 GMT]]></title><description><![CDATA[<p>Bitte bleib bei einem Thema. Besonders wenn es ein komplett anderes ist als eigentlich diskutiert wird. Ich habe deine neue Frage abgespalten, hier geht es weiter:<br />
<a href="http://www.c-plusplus.net/forum/p2223137" rel="nofollow">http://www.c-plusplus.net/forum/p2223137</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2223147</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2223147</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Thu, 14 Jun 2012 13:34:16 GMT</pubDate></item><item><title><![CDATA[Reply to Komisches Ergebnis einer Rechnung mit float on Fri, 15 Jun 2012 12:03:22 GMT]]></title><description><![CDATA[<p>ja sry hatte es nur direkt hierhin geschrieben weil ich ja die lösung für den rechner testen wollte</p>
<p>EDIT: hmm der neue code ist so:</p>
<pre><code>#include&lt;iostream&gt;
using namespace std;

int main()
{
	float u;			//Deklarierungen
	float P;
	float r;
	int a;				//a für Auswahl

	P = 3;		//Definierung Pi

	cout &lt;&lt; &quot;Was wollen sie berechnen?&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;1: Umfang&quot; &lt;&lt; endl &lt;&lt; &quot;2: Fläche&quot; &lt;&lt; endl;
	cin &gt;&gt; a;

	if (a == 1)
	{
		u = 2 * r * P;
		cout &lt;&lt; &quot;Sie haben Umfang gewählt.&quot; &lt;&lt; endl;
		cout &lt;&lt; &quot;Geben sie den Radius ein:&quot; &lt;&lt; endl;
		cin &gt;&gt; r;
		cout &lt;&lt; &quot;Der Umfang beträgt:&quot; &lt;&lt; u &lt;&lt; endl;
	}
	return 0;

}
</code></pre>
<p>jedoch immernoch das gleiche problem oO<br />
ergebnis ist mit radius 3:<br />
3.53282e-038<br />
tja un jetzt :/?</p>
<p>EDIT: ok das hab ich eben selbst gemerkt. ich dachte die Rechnung muss nur in der gleichen Klammer sein aber mir ist aufgefallen dass das problem ja war dass r nochnicht definiert war. hab ich die rechnung hinter die eingabe von r gepackt und es klappt <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="😃"
    /><br />
fertig is jetzt so:</p>
<pre><code>#include&lt;iostream&gt;
using namespace std;

int main()
{
	float u;			//Deklarierungen
	float P;
	float r;
	float f;
	int a;				//a für Auswahl

	P = 3.141592;		//Definierung Pi

	cout &lt;&lt; &quot;Was wollen sie berechnen?&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;1: Umfang&quot; &lt;&lt; endl &lt;&lt; &quot;2: Fläche&quot; &lt;&lt; endl;
	cin &gt;&gt; a;

	if (a == 1)
	{
		cout &lt;&lt; &quot;Sie haben Umfang gewählt.&quot; &lt;&lt; endl;
		cout &lt;&lt; &quot;Geben sie den Radius ein:&quot; &lt;&lt; endl;
		cin &gt;&gt; r;
		u = 2 * r * P;
		cout &lt;&lt; &quot;Der Umfang beträgt:&quot; &lt;&lt; u &lt;&lt; endl;
	}

	if (a == 2)
	{
		cout &lt;&lt; &quot;Sie haben Fläche gewählt.&quot; &lt;&lt; endl;
		cout &lt;&lt; &quot;Geben sie den Radius ein:&quot; &lt;&lt; endl;
		cin &gt;&gt; r;
		f = r * r * P;
		cout &lt;&lt; &quot;Die Fläche beträgt:&quot; &lt;&lt; f &lt;&lt; endl;
	}
	return 0;

}
</code></pre>
<p>fertig ist mein Kreisrechner <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f576.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--sunglasses"
      title=":sunglasses:"
      alt="🕶"
    /><br />
jetzt mach ich noch mehr funktionen dazu...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2223151</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2223151</guid><dc:creator><![CDATA[Golol]]></dc:creator><pubDate>Fri, 15 Jun 2012 12:03:22 GMT</pubDate></item></channel></rss>