<?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[Hilfe: Programm funktioniert nicht wenn ein cout befehl fehlt]]></title><description><![CDATA[<p>Ich fange gerade an C++ zu lernen und hatte mir das Ziel gesetz ein Programm zu schreiben welches Tested ob eine Zahl eine Primzahl ist.<br />
Nach einigem rumprobieren funktionierte das Programm dann auch, aber wenn ich einen bestimmten (zu testzwecken genutzten) cout Befehl lösche funktioniert das Programm nicht mehr.<br />
Zusätzlich funktioniert es nicht wenn ich den Debug Modus benutze. (Also nur in Release Modus)<br />
Ich benutze Code::Blocks version 12.11.<br />
Der problematische cout Befehl liegt in Zeile 53.<br />
Ich kann einfach nicht verstehen warum das Programm ohne diesen Befehl nicht funktioniert.<br />
LG<br />
Sven</p>
<pre><code>//PrimzahlenTest
#include &lt;iostream&gt;
using namespace std;

int iswhole(float number);
int isprime(float in);

int main()
{
//VAR
float x;

cout &lt;&lt; &quot;Primzahlentester\nGeben sie die Zahl ein!&quot; &lt;&lt; endl;
cin &gt;&gt; x;

cout &lt;&lt; isprime(x) &lt;&lt; endl;

int zz;
cout &lt;&lt; &quot;Geben sie eine belibige Zahl + ENTER ein&quot; &lt;&lt; endl;
cin &gt;&gt; zz;

return 0;
}
int iswhole(float number)
{
    bool truefalse;

    while(number &gt;= 1)
    {
        number--;
    }
    if(number==0)
    {
    truefalse = 1;
    }
    else
    {
    truefalse = 0;
    }
    return truefalse;

}
int isprime(float input)
{
bool bprime=0;
int sum;
int loop = input-1;
float test;

while(loop &gt; 1)
 {
    test = input/loop;
    cout &lt;&lt;&quot;&quot;; //&lt;--Wenn ich diese Zeile lösche funktioniert das Programm nicht mehr :(
    sum+=iswhole(test);
    loop--;
 }
if (sum==0)
    {
    bprime = 1;
    }
return bprime;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/317638/hilfe-programm-funktioniert-nicht-wenn-ein-cout-befehl-fehlt</link><generator>RSS for Node</generator><lastBuildDate>Tue, 28 Jul 2026 19:29:16 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/317638.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 15 Jun 2013 17:15:59 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Hilfe: Programm funktioniert nicht wenn ein cout befehl fehlt on Sat, 15 Jun 2013 17:15:59 GMT]]></title><description><![CDATA[<p>Ich fange gerade an C++ zu lernen und hatte mir das Ziel gesetz ein Programm zu schreiben welches Tested ob eine Zahl eine Primzahl ist.<br />
Nach einigem rumprobieren funktionierte das Programm dann auch, aber wenn ich einen bestimmten (zu testzwecken genutzten) cout Befehl lösche funktioniert das Programm nicht mehr.<br />
Zusätzlich funktioniert es nicht wenn ich den Debug Modus benutze. (Also nur in Release Modus)<br />
Ich benutze Code::Blocks version 12.11.<br />
Der problematische cout Befehl liegt in Zeile 53.<br />
Ich kann einfach nicht verstehen warum das Programm ohne diesen Befehl nicht funktioniert.<br />
LG<br />
Sven</p>
<pre><code>//PrimzahlenTest
#include &lt;iostream&gt;
using namespace std;

int iswhole(float number);
int isprime(float in);

int main()
{
//VAR
float x;

cout &lt;&lt; &quot;Primzahlentester\nGeben sie die Zahl ein!&quot; &lt;&lt; endl;
cin &gt;&gt; x;

cout &lt;&lt; isprime(x) &lt;&lt; endl;

int zz;
cout &lt;&lt; &quot;Geben sie eine belibige Zahl + ENTER ein&quot; &lt;&lt; endl;
cin &gt;&gt; zz;

return 0;
}
int iswhole(float number)
{
    bool truefalse;

    while(number &gt;= 1)
    {
        number--;
    }
    if(number==0)
    {
    truefalse = 1;
    }
    else
    {
    truefalse = 0;
    }
    return truefalse;

}
int isprime(float input)
{
bool bprime=0;
int sum;
int loop = input-1;
float test;

while(loop &gt; 1)
 {
    test = input/loop;
    cout &lt;&lt;&quot;&quot;; //&lt;--Wenn ich diese Zeile lösche funktioniert das Programm nicht mehr :(
    sum+=iswhole(test);
    loop--;
 }
if (sum==0)
    {
    bprime = 1;
    }
return bprime;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2331375</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2331375</guid><dc:creator><![CDATA[Aspecsi]]></dc:creator><pubDate>Sat, 15 Jun 2013 17:15:59 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe: Programm funktioniert nicht wenn ein cout befehl fehlt on Sat, 15 Jun 2013 17:22:24 GMT]]></title><description><![CDATA[<p>Hier erstmal der Code für mitlesende, formatiert und in die passenden Tags gesetzt.</p>
<pre><code>//PrimzahlenTest 
#include &lt;iostream&gt; 
using namespace std; 

int iswhole(float number); 
int isprime(float in); 

int main() 
{ 
	//VAR 
	float x; 

	cout &lt;&lt; &quot;Primzahlentester\nGeben sie die Zahl ein!&quot; &lt;&lt; endl; 
	cin &gt;&gt; x; 

	cout &lt;&lt; isprime(x) &lt;&lt; endl; 

	int zz; 
	cout &lt;&lt; &quot;Geben sie eine belibige Zahl + ENTER ein&quot; &lt;&lt; endl; 
	cin &gt;&gt; zz; 
}

int iswhole(float number) 
{ 
    bool truefalse; 

    while(number &gt;= 1) 
        number--; 

    if(number==0) 
		truefalse = 1; 

    else 
		truefalse = 0; 

    return truefalse; 

}

int isprime(float input) 
{ 
	bool bprime=0; 
	int sum; 
	int loop = input-1; 
	float test; 

	while(loop &gt; 1) 
	{ 
		test = input/loop; 
		cout &lt;&lt;&quot;&quot;; //&lt;--Wenn ich diese Zeile lösche funktioniert das Programm nicht mehr :( 
		sum+=iswhole(test); 
		loop--; 
	} 

	if (sum==0) 
		bprime = 1; 

	return bprime; 
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2331376</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2331376</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Sat, 15 Jun 2013 17:22:24 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe: Programm funktioniert nicht wenn ein cout befehl fehlt on Sat, 15 Jun 2013 17:22:40 GMT]]></title><description><![CDATA[<p>&quot;Funktioniert nicht&quot; ist keine Fehlerbeschreibung. Genaue Fehlermeldung?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2331377</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2331377</guid><dc:creator><![CDATA[Jonas OSDever]]></dc:creator><pubDate>Sat, 15 Jun 2013 17:22:40 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe: Programm funktioniert nicht wenn ein cout befehl fehlt on Sat, 15 Jun 2013 17:26:05 GMT]]></title><description><![CDATA[<pre><code>cout &lt;&lt;&quot;&quot;; //&lt;--Wenn ich diese Zeile lösche funktioniert das Programm nicht mehr :(
</code></pre>
<p>Das ist nicht möglich. Dieses Statement hat praktisch überhaupt keine Auswirkung auf dein Programm.<br />
Gib mal eine genaue Fehlerbeschreibung. Ich versuche gleich mal, das Programm zu starten und sehe es mir an.</p>
<p>Ein Problem bei deinem Code ist, dass du Fließkommazahlen verwendest, obwohl du das überhaupt nicht brauchst - und dadurch alles durcheinander bringst. Wieso verwendest du also <code>float</code> statt <code>unsigned</code> ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2331379</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2331379</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Sat, 15 Jun 2013 17:26:05 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe: Programm funktioniert nicht wenn ein cout befehl fehlt on Sat, 15 Jun 2013 17:27:55 GMT]]></title><description><![CDATA[<p>Jonas OSDever schrieb:</p>
<blockquote>
<p>&quot;Funktioniert nicht&quot; ist keine Fehlerbeschreibung. Genaue Fehlermeldung?</p>
</blockquote>
<p>Das Programm giebt anstelle von entweder 0 oder 1 (Primzahl oder Keine Primzahl)<br />
nur 0 aus egal ob es eine Primzahl ist oder nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2331381</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2331381</guid><dc:creator><![CDATA[Aspecsi]]></dc:creator><pubDate>Sat, 15 Jun 2013 17:27:55 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe: Programm funktioniert nicht wenn ein cout befehl fehlt on Sat, 15 Jun 2013 17:29:59 GMT]]></title><description><![CDATA[<p>cout&lt;&lt;&quot;&quot;; verwendet man gerne, um den Optimierer in die Knie zu zwingen. Damit leere Schleifen nicht wegoptimiert werden.</p>
<p>Dein Prog bewertet 7 bei mir im Debug-Modus als Primzahl und im Release-Modus als Nicht-Primzahl.</p>
<p>Das deutet darauf hin, daß Du was gemacht hast, was undefiniertes Verhalten erzeugt. Auf Anhieb sehe ich, daß sum nicht initialisiert wurde. Ob's das schon war?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2331383</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2331383</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sat, 15 Jun 2013 17:29:59 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe: Programm funktioniert nicht wenn ein cout befehl fehlt on Sat, 15 Jun 2013 17:30:25 GMT]]></title><description><![CDATA[<p>Du hast zumindest mal einen klassischen Anfängerfehler gemacht: <code>error C4700: uninitialized local variable 'sum' used</code></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2331384</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2331384</guid><dc:creator><![CDATA[out]]></dc:creator><pubDate>Sat, 15 Jun 2013 17:30:25 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe: Programm funktioniert nicht wenn ein cout befehl fehlt on Sat, 15 Jun 2013 17:42:48 GMT]]></title><description><![CDATA[<p>Sone schrieb:</p>
<blockquote>
<pre><code>cout &lt;&lt;&quot;&quot;; //&lt;--Wenn ich diese Zeile lösche funktioniert das Programm nicht mehr :(
</code></pre>
<p>Das ist nicht möglich. Dieses Statement hat praktisch überhaupt keine Auswirkung auf dein Programm.<br />
Gib mal eine genaue Fehlerbeschreibung. Ich versuche gleich mal, das Programm zu starten und sehe es mir an.</p>
</blockquote>
<p>Ein Problem bei deinem Code ist, dass du Fließkommazahlen verwendest, obwohl du das überhaupt nicht brauchst - und dadurch alles durcheinander bringst. Wieso verwendest du also <code>float</code> statt <code>unsigned</code> ?[/quote]<br />
Das Programm giebt (egal ob Primzahl oder nicht) nur 0 aus anselle von 0 (Keine Primzahl) oder 1 (Primzahl)<br />
Es funktioniert aber auch nicht im Debug modus.</p>
<p>Sone schrieb:</p>
<blockquote>
<p>Ein Problem bei deinem Code ist, dass du Fließkommazahlen verwendest, obwohl du das überhaupt nicht brauchst - und dadurch alles durcheinander bringst. Wieso verwendest du also <code>float</code> statt <code>unsigned</code> ?</p>
</blockquote>
<p>Ich habe (wie bereits gesagt) gerade erst angefangen C++ zu lernen.<br />
Ich wusste bis gerade noch nicht einmal das es etwas wie unsigned giebt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2331385</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2331385</guid><dc:creator><![CDATA[Aspecsi]]></dc:creator><pubDate>Sat, 15 Jun 2013 17:42:48 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe: Programm funktioniert nicht wenn ein cout befehl fehlt on Sat, 15 Jun 2013 17:42:02 GMT]]></title><description><![CDATA[<p>volkard schrieb:</p>
<blockquote>
<p>Auf Anhieb sehe ich, daß sum nicht initialisiert wurde. Ob's das schon war?</p>
</blockquote>
<p>initialisieren heiß Wert zuweißen, oder ?<br />
Jedenfalls funktioniert das Programm jetzt, habe einfach.</p>
<pre><code>int sum;
</code></pre>
<p>zu</p>
<pre><code>int sum=0;
</code></pre>
<p>geändert und jetzt Funktioniert es.<br />
Danke für helfen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2331387</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2331387</guid><dc:creator><![CDATA[Aspecsi]]></dc:creator><pubDate>Sat, 15 Jun 2013 17:42:02 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe: Programm funktioniert nicht wenn ein cout befehl fehlt on Sat, 15 Jun 2013 17:50:12 GMT]]></title><description><![CDATA[<p><s>Du hast ja schon deine Antwort gehabt. Uninitialisierte Variable. Aber wie gesagt, der Rest des Programms ist auch nicht gerade der beste. Warum ein rekursiver Ansatz fuer Primzahlen? Warum float?</s></p>
<p>EDIT: Ich brauch ne Brille oder n groesseren Bildschirm...</p>
<pre><code class="language-cpp">bool isPrime(unsigned number)
{
    if(number &lt; 2)
         return false;

    for(unsigned i = 2; i &lt; number; ++i)
        if(number % i == 0)
            return false;

    return true;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2331389</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2331389</guid><dc:creator><![CDATA[Jonas OSDever]]></dc:creator><pubDate>Sat, 15 Jun 2013 17:50:12 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe: Programm funktioniert nicht wenn ein cout befehl fehlt on Sat, 15 Jun 2013 17:45:59 GMT]]></title><description><![CDATA[<p>Aspecsi schrieb:</p>
<blockquote>
<p>Sone schrieb:</p>
<blockquote>
<pre><code>cout &lt;&lt;&quot;&quot;; //&lt;--Wenn ich diese Zeile lösche funktioniert das Programm nicht mehr :(
</code></pre>
<p>Das ist nicht möglich. Dieses Statement hat praktisch überhaupt keine Auswirkung auf dein Programm.<br />
Gib mal eine genaue Fehlerbeschreibung. Ich versuche gleich mal, das Programm zu starten und sehe es mir an.</p>
</blockquote>
<p>Ein Problem bei deinem Code ist, dass du Fließkommazahlen verwendest, obwohl du das überhaupt nicht brauchst - und dadurch alles durcheinander bringst. Wieso verwendest du also <code>float</code> statt <code>unsigned</code> ?</p>
</blockquote>
<p>Das Programm giebt (egal ob Primzahl oder nicht) nur 0 aus anselle von 0 (Keine Primzahl) oder 1 (Primzahl)<br />
Es funktioniert aber auch nicht im Debug modus.</p>
<p>Sone schrieb:</p>
<blockquote>
<p>Ein Problem bei deinem Code ist, dass du Fließkommazahlen verwendest, obwohl du das überhaupt nicht brauchst - und dadurch alles durcheinander bringst. Wieso verwendest du also <code>float</code> statt <code>unsigned</code> ?</p>
</blockquote>
<p>Ich habe (wie bereits gesagt) gerade erst angefangen C++ zu lernen.<br />
Ich wusste bis gerade noch nicht einmal das es etwas wie unsigned giebt.[/quote]<br />
vergiss erstmal unsigned.<br />
denk dir sones vorschlag mit int.<br />
&quot;wieso verwendest du float statt int&quot; wäre dann die frage.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2331390</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2331390</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sat, 15 Jun 2013 17:45:59 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe: Programm funktioniert nicht wenn ein cout befehl fehlt on Sat, 15 Jun 2013 17:47:51 GMT]]></title><description><![CDATA[<p>Jonas OSDever schrieb:</p>
<blockquote>
<p>Warum ein rekursiver Ansatz fuer Primzahlen?</p>
</blockquote>
<p>Da haste aber geschielt, alös Du den rekursiven Ansatz im Programm erkannt hast.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2331391</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2331391</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sat, 15 Jun 2013 17:47:51 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe: Programm funktioniert nicht wenn ein cout befehl fehlt on Sat, 15 Jun 2013 17:49:36 GMT]]></title><description><![CDATA[<p>Ach Mist, hab statt <code>iswhole</code>  <code>isprime</code> gelesen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2331392</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2331392</guid><dc:creator><![CDATA[Jonas OSDever]]></dc:creator><pubDate>Sat, 15 Jun 2013 17:49:36 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe: Programm funktioniert nicht wenn ein cout befehl fehlt on Sat, 15 Jun 2013 17:56:22 GMT]]></title><description><![CDATA[<p>@Jonas OSDever<br />
Ich sehe das doch richtig das unsigned(int) für ganze positive zahlen ist, Richtig ?<br />
Ich habe einfach versucht (zu übungszwecken) selber ein Programm zu schreiben das Priemzahlen als solche kennzeichnen kann.<br />
Ich hatte zuerst einen ganz Falschen ansatz um die Primzahlen zu erkennen,<br />
daher die unnötigen float Variabeln.<br />
Ich werde den Code wohl noch einmal aufräumen müssen. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /><br />
Danke auch dir für die Hilfe .</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2331393</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2331393</guid><dc:creator><![CDATA[Aspecsi]]></dc:creator><pubDate>Sat, 15 Jun 2013 17:56:22 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe: Programm funktioniert nicht wenn ein cout befehl fehlt on Wed, 11 Jun 2014 23:26:23 GMT]]></title><description><![CDATA[<p>...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2331395</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2331395</guid><dc:creator><![CDATA[Swordfish]]></dc:creator><pubDate>Wed, 11 Jun 2014 23:26:23 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe: Programm funktioniert nicht wenn ein cout befehl fehlt on Sat, 15 Jun 2013 20:29:27 GMT]]></title><description><![CDATA[<blockquote>
<p>1 (Primzahl)</p>
</blockquote>
<p>Ich glaube, ich habe dich missverstanden.</p>
<p>Edit: Ja, habe ich. Hätte ich dir auch nicht zugetraut, nie nie.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2331431</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2331431</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Sat, 15 Jun 2013 20:29:27 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe: Programm funktioniert nicht wenn ein cout befehl fehlt on Wed, 11 Jun 2014 23:26:31 GMT]]></title><description><![CDATA[<p>...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2331434</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2331434</guid><dc:creator><![CDATA[Swordfish]]></dc:creator><pubDate>Wed, 11 Jun 2014 23:26:31 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe: Programm funktioniert nicht wenn ein cout befehl fehlt on Sat, 15 Jun 2013 20:43:32 GMT]]></title><description><![CDATA[<p>P.S.: <code>unsigned</code> ist die Kurzform von <code>unsigned int</code> , und <code>unsigned int</code> ist praktisch <code>int</code> - nur dass keine negativen Zahlen gespeichert werden können, und sich dadurch der Wertebereich für positive Zahlen verdoppelt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2331437</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2331437</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Sat, 15 Jun 2013 20:43:32 GMT</pubDate></item></channel></rss>