<?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[Ein &amp;quot;double-&amp;quot;ergebnis nicht aus Integern-Variablen möglich?]]></title><description><![CDATA[<p>Guten Tag,<br />
ich habe folgenden Code-Ausschnitt für Euch:</p>
<pre><code class="language-cpp">srand(time(0));
		int zufallszahl;
		double anzahl_richtige = 0;
		double anzahl_falsche = 0;
		double erfolg;
		double anzahl_vokabeln = 0;
		while(1) {
			std::string eingabe_englisch;
			zufallszahl = rand() % anzahl_zeilen;
			erfolg = anzahl_richtige / anzahl_vokabeln * 100;
			anzahl_vokabeln++;
			system(&quot;CLS&quot;);
			std::cout &lt;&lt; &quot;Richtige: &quot; &lt;&lt; anzahl_richtige &lt;&lt; &quot;	Falsche: &quot; &lt;&lt; anzahl_falsche &lt;&lt; &quot;	Erfolg: &quot; &lt;&lt; erfolg &lt;&lt; &quot;%\n\n\n&quot;;
			std::cout &lt;&lt; &quot;Deutsch:  &quot; &lt;&lt; deutsch[zufallszahl] &lt;&lt; '\n';
			std::cout &lt;&lt; &quot;Englisch: &quot;;
			std::cin  &gt;&gt; eingabe_englisch;
			if(eingabe_englisch == englisch[zufallszahl]) {
				std::cout &lt;&lt; &quot;Richtig!&quot;;
				anzahl_richtige++;
				_getch();
			}
			else {
				std::cout &lt;&lt; &quot;Falsch: &quot; &lt;&lt; englisch[zufallszahl];
				anzahl_falsche++;
				_getch();
			}
		}
</code></pre>
<p>Und zwar ist es ein Teil meines Lernprogramms. Es sollen zufällige Vokabeln aus einer Textdatei eingelesen werden (funktioniert). Nun soll der Benutzer eine Vokabel auf englisch eingeben, dann wird sie mit der Richtigen verglichen und ausgewertet. Das funktioniert auch alles, nur wenn ich Änderung an folgendem Ausschnitt vornehme</p>
<pre><code class="language-cpp">double anzahl_richtige = 0;
		double anzahl_falsche = 0;
		double erfolg;
		double anzahl_vokabeln = 0;
</code></pre>
<p>Und ersetze durch</p>
<pre><code class="language-cpp">int anzahl_richtige = 0;
		int anzahl_falsche = 0;
		double erfolg;
		int anzahl_vokabeln = 0;
</code></pre>
<p>dann ist irgendwas falsch bei der Berechnung</p>
<pre><code class="language-cpp">erfolg = anzahl_richtige / anzahl_vokabeln * 100;
</code></pre>
<p>denn das Programm hängt sich dann auf.<br />
Wisst ihr warum? Denn eigentlich müsste folgender Pseudocode doch funktionieren</p>
<pre><code>double erfolg = int zahl1 / int zahl2
</code></pre>
<p>:xmas1:</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/296736/ein-quot-double-quot-ergebnis-nicht-aus-integern-variablen-möglich</link><generator>RSS for Node</generator><lastBuildDate>Fri, 14 Aug 2026 18:42:05 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/296736.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 11 Dec 2011 13:31:04 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Ein &amp;quot;double-&amp;quot;ergebnis nicht aus Integern-Variablen möglich? on Sun, 11 Dec 2011 13:31:04 GMT]]></title><description><![CDATA[<p>Guten Tag,<br />
ich habe folgenden Code-Ausschnitt für Euch:</p>
<pre><code class="language-cpp">srand(time(0));
		int zufallszahl;
		double anzahl_richtige = 0;
		double anzahl_falsche = 0;
		double erfolg;
		double anzahl_vokabeln = 0;
		while(1) {
			std::string eingabe_englisch;
			zufallszahl = rand() % anzahl_zeilen;
			erfolg = anzahl_richtige / anzahl_vokabeln * 100;
			anzahl_vokabeln++;
			system(&quot;CLS&quot;);
			std::cout &lt;&lt; &quot;Richtige: &quot; &lt;&lt; anzahl_richtige &lt;&lt; &quot;	Falsche: &quot; &lt;&lt; anzahl_falsche &lt;&lt; &quot;	Erfolg: &quot; &lt;&lt; erfolg &lt;&lt; &quot;%\n\n\n&quot;;
			std::cout &lt;&lt; &quot;Deutsch:  &quot; &lt;&lt; deutsch[zufallszahl] &lt;&lt; '\n';
			std::cout &lt;&lt; &quot;Englisch: &quot;;
			std::cin  &gt;&gt; eingabe_englisch;
			if(eingabe_englisch == englisch[zufallszahl]) {
				std::cout &lt;&lt; &quot;Richtig!&quot;;
				anzahl_richtige++;
				_getch();
			}
			else {
				std::cout &lt;&lt; &quot;Falsch: &quot; &lt;&lt; englisch[zufallszahl];
				anzahl_falsche++;
				_getch();
			}
		}
</code></pre>
<p>Und zwar ist es ein Teil meines Lernprogramms. Es sollen zufällige Vokabeln aus einer Textdatei eingelesen werden (funktioniert). Nun soll der Benutzer eine Vokabel auf englisch eingeben, dann wird sie mit der Richtigen verglichen und ausgewertet. Das funktioniert auch alles, nur wenn ich Änderung an folgendem Ausschnitt vornehme</p>
<pre><code class="language-cpp">double anzahl_richtige = 0;
		double anzahl_falsche = 0;
		double erfolg;
		double anzahl_vokabeln = 0;
</code></pre>
<p>Und ersetze durch</p>
<pre><code class="language-cpp">int anzahl_richtige = 0;
		int anzahl_falsche = 0;
		double erfolg;
		int anzahl_vokabeln = 0;
</code></pre>
<p>dann ist irgendwas falsch bei der Berechnung</p>
<pre><code class="language-cpp">erfolg = anzahl_richtige / anzahl_vokabeln * 100;
</code></pre>
<p>denn das Programm hängt sich dann auf.<br />
Wisst ihr warum? Denn eigentlich müsste folgender Pseudocode doch funktionieren</p>
<pre><code>double erfolg = int zahl1 / int zahl2
</code></pre>
<p>:xmas1:</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2155713</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2155713</guid><dc:creator><![CDATA[Feuerkelch]]></dc:creator><pubDate>Sun, 11 Dec 2011 13:31:04 GMT</pubDate></item><item><title><![CDATA[Reply to Ein &amp;quot;double-&amp;quot;ergebnis nicht aus Integern-Variablen möglich? on Sun, 11 Dec 2011 13:32:40 GMT]]></title><description><![CDATA[<p>Wenn du zwei ints dividierst, kommt auch int raus. Die Lösung: Schreib eine Multiplikation mit 1.0 dazu.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2155715</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2155715</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Sun, 11 Dec 2011 13:32:40 GMT</pubDate></item><item><title><![CDATA[Reply to Ein &amp;quot;double-&amp;quot;ergebnis nicht aus Integern-Variablen möglich? on Sun, 11 Dec 2011 13:36:15 GMT]]></title><description><![CDATA[<p>Achso okay funktioniert, danke. Irgendwie komisch finde ich. Ich meine mich zu erinnern, dass es beim Dev C++ Compiler funktionierte (ohne Multiplikation von 1.0)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2155718</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2155718</guid><dc:creator><![CDATA[Feuerkelch]]></dc:creator><pubDate>Sun, 11 Dec 2011 13:36:15 GMT</pubDate></item><item><title><![CDATA[Reply to Ein &amp;quot;double-&amp;quot;ergebnis nicht aus Integern-Variablen möglich? on Sun, 11 Dec 2011 14:03:51 GMT]]></title><description><![CDATA[<p>Du kannst auch <code>static_cast&lt;double&gt;(operand)</code> verwenden. Natürlich vor der Division.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2155724</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2155724</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Sun, 11 Dec 2011 14:03:51 GMT</pubDate></item><item><title><![CDATA[Reply to Ein &amp;quot;double-&amp;quot;ergebnis nicht aus Integern-Variablen möglich? on Sun, 11 Dec 2011 14:08:21 GMT]]></title><description><![CDATA[<p>Feuerkelch schrieb:</p>
<blockquote>
<p>Achso okay funktioniert, danke. Irgendwie komisch finde ich. Ich meine mich zu erinnern, dass es beim Dev C++ Compiler funktionierte (ohne Multiplikation von 1.0)</p>
</blockquote>
<p>Das wäre ein Fehler im Compiler, denn dieses Verhalten ist so vorgeschrieben (und das hat auch gute Gründe, die du jetzt vielleicht nicht siehst). Jetzt werden einige sagen, dass dies bei Dev C++ kein Wunder ist, aber so krasse Fehler hat der nun auch nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2155725</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2155725</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Sun, 11 Dec 2011 14:08:21 GMT</pubDate></item><item><title><![CDATA[Reply to Ein &amp;quot;double-&amp;quot;ergebnis nicht aus Integern-Variablen möglich? on Sun, 11 Dec 2011 14:16:35 GMT]]></title><description><![CDATA[<p>Jetzt hab ich ein anderes Problem. Der selbe Codeausschnitt wie oben, nur dass ich jetzt statt einer einfachen &quot;cin-&quot; Eingabe eine &quot;con.getline()&quot; funktion nutzen möchte (bei Leerzeicheneingabe)</p>
<pre><code class="language-cpp">srand(time(0));
		int zufallszahl;
		int anzahl_richtige = 0;
		int anzahl_falsche = 0;
		int anzahl_vokabeln = 0;
		double erfolg;
		while(1) {
			char eingabe_englisch[100];
			zufallszahl = rand() % anzahl_zeilen;
			erfolg = (anzahl_richtige * 1.0) / (anzahl_vokabeln * 1.0) * 100;
			anzahl_vokabeln++;
			system(&quot;CLS&quot;);
			std::cout &lt;&lt; &quot;Richtige: &quot; &lt;&lt; anzahl_richtige &lt;&lt; &quot;	Falsche: &quot; &lt;&lt; anzahl_falsche &lt;&lt; &quot;	Erfolg: &quot; &lt;&lt; erfolg &lt;&lt; &quot;%\n\n\n&quot;;
			std::cout &lt;&lt; &quot;Deutsch:  &quot; &lt;&lt; deutsch[zufallszahl] &lt;&lt; '\n';
			std::cout &lt;&lt; &quot;Englisch: &quot;;
			std::cin.getline(eingabe_englisch, 100, '\n');
			if(eingabe_englisch == englisch[zufallszahl]) {
				std::cout &lt;&lt; &quot;Richtig!&quot;;
				anzahl_richtige++;
				_getch();
			}
			else {
				std::cout &lt;&lt; &quot;Falsch: &quot; &lt;&lt; englisch[zufallszahl];
				anzahl_falsche++;
				_getch();
			}
		}
</code></pre>
<p>Funktioniert auch, aber leider wird das erste mal eingeben übersprungen und mir schmeißt das Programm einfach ein Falsch hin. Wenn ich mir eine neue Vokabel abfrage, dann funktioniert es. Es ist also nur am Start der Abfrage. <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/2155728</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2155728</guid><dc:creator><![CDATA[Feuerkelch]]></dc:creator><pubDate>Sun, 11 Dec 2011 14:16:35 GMT</pubDate></item><item><title><![CDATA[Reply to Ein &amp;quot;double-&amp;quot;ergebnis nicht aus Integern-Variablen möglich? on Sun, 11 Dec 2011 14:29:05 GMT]]></title><description><![CDATA[<p>Schreib mal über das getline ein std::cin.ignore();.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2155731</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2155731</guid><dc:creator><![CDATA[freaky]]></dc:creator><pubDate>Sun, 11 Dec 2011 14:29:05 GMT</pubDate></item><item><title><![CDATA[Reply to Ein &amp;quot;double-&amp;quot;ergebnis nicht aus Integern-Variablen möglich? on Sun, 11 Dec 2011 14:34:56 GMT]]></title><description><![CDATA[<p>Okay funktioniert, kommt mir aber irgendwie gefuscht vor <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>
]]></description><link>https://www.c-plusplus.net/forum/post/2155733</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2155733</guid><dc:creator><![CDATA[Feuerkelch]]></dc:creator><pubDate>Sun, 11 Dec 2011 14:34:56 GMT</pubDate></item><item><title><![CDATA[Reply to Ein &amp;quot;double-&amp;quot;ergebnis nicht aus Integern-Variablen möglich? on Sun, 11 Dec 2011 19:18:52 GMT]]></title><description><![CDATA[<p>Feuerkelch schrieb:</p>
<blockquote>
<p>Okay funktioniert, kommt mir aber irgendwie gefuscht vor <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>
</blockquote>
<p>Ist es aber nicht.<br />
ignore ist eine Funktion von istream und dient dazu, <s>z</s>Zeichen aus einem <s>s</s>Stream bis zu einem <s>d</s>Delimitter oder der angegebenen Anzahl zu ignorieren.</p>
<pre><code class="language-cpp">istream&amp;  ignore ( streamsize n = 1, int delim = EOF );//Deklaration
</code></pre>
<p>Es wird also bei der &quot;default&quot; Variante einfach ein Zeichen übersprungen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2155853</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2155853</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Sun, 11 Dec 2011 19:18:52 GMT</pubDate></item></channel></rss>