<?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[PQ Formel Lösen]]></title><description><![CDATA[<p>Hi<br />
Ich habe ein Programm geschrieben das die PQ Formel lösen soll. An anfang werden P und Q eingelesen und dan Arbeiter das Programm. Die Ergebnise für X1 und X2 die es lösst sind auch richtig. Allerdings setzt es vor die Ausgabe der Ergebnisse immer<br />
0x4375e4<br />
und dann kommt das richtige Ergebnis. Durch ausprobieren bin ich mir Mitlerweile sicher das das Problem beim + bzw. - Rechnen in der Ausgabe Funktion entsteht</p>
<p>Wisst ihr woran das liegen kann</p>
<p>Hier der Quelltext:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;stdlib.h&gt;

using namespace std;

float Wz=0;
float N=1; 
float W=0;
float N1=0;
float N2=0; 
float P=0; 
float Q=0; 
float P2=0; 
float X1=0; 
float X2=0; 

//FUNKTIONEN: 

 //Funktionsprototyp E_PQ 

    void E_PQ (void);

    //Funktionsdefinition E_PQ

    void E_PQ (void)
    {

    cout &lt;&lt;&quot;Bitte geben Sie P ein&quot;; 
    cin  &gt;&gt;P;
    cout &lt;&lt;&quot;Bitte geben Sie Q ein&quot;; 
    cin &gt;&gt;Q; 
    cout &lt;&lt;&quot;\n&quot;; 

    //P/2berechnen.
    P2=P/2; 
    }    

        //Funktionsprototyp B_PQ
        float B_PQ (float, float, float );

        //Funktionsdefinition B_PQ
        float B_PQ(float Wz)
             {

            //PQ_Formel

            //Berechnen Wurzle (alle Zahlen die unter der Wurzel stehen werden zusammengerechnet: 
            Wz=P2*P2-Q;

              do{

              //Wurzel Ziehen so oft bis =Wz ist.
              N1=Wz/N;
              N2=N+N1;
              N=N2/2;

              W=N*N;    
              } while (W&gt;(Wz+0.01));  
               //N ist jetzt der Ausdruck der unter der Wurzel steht 

               cout &lt;&lt;N; 
               cout &lt;&lt;&quot;\n&quot;;
                return N; 
              }      

  //PQ_Ausgabe Prototyp 

  void PQ_Ausgabe (float); 

 //PQ_Ausgabe Definition (N ist der Ausdruck unter der Wurzel) 

 void PQ_Ausgabe (float N)
 {
  cout &lt;&lt; &quot;Vor dem Tausch:\n &quot;;
  cout &lt;&lt; P2; 
  cout &lt;&lt; &quot;\n&quot;; 
  //Forzeichen Tausch 
  P2=P2*-1;

  cout &lt;&lt;&quot;Nach dem Tausch:\n &quot;;
  cout &lt;&lt;P2; 
  cout &lt;&lt;&quot;\n&quot;;

  cout &lt;&lt;&quot;Wurzel nach der Übergabe\n&quot;; 
  cout &lt;&lt;N;
  cout &lt;&lt;&quot;\n&quot;;

  //Hier entsteht das Problem! 
  X1=P2+N;
  X2=P2-N;

  cout &lt;&lt;&quot;X1:&quot; &lt;&lt; cout &lt;&lt;X1; cout &lt;&lt;&quot;\n&quot;;
  cout &lt;&lt;&quot;X2:&quot; &lt;&lt; cout &lt;&lt;X2; cout &lt;&lt;&quot;\n&quot;;

 }     

//HAUPTPROGRAMM

int main(int argc, char *argv[])
{
    //Funktionsaufruf E_PQ (Eingabe) 
    E_PQ(); 

    //Funktionsaufruf B_PQ (Berechnung) 
    N = B_PQ (Wz);

    //Funktionsaufruf PQ_Ausgabe 
    PQ_Ausgabe (N);

  system(&quot;PAUSE&quot;);	
  return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/195403/pq-formel-lösen</link><generator>RSS for Node</generator><lastBuildDate>Wed, 30 Sep 2026 02:38:25 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/195403.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 17 Oct 2007 11:17:47 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to PQ Formel Lösen on Wed, 17 Oct 2007 11:23:03 GMT]]></title><description><![CDATA[<p>Hi<br />
Ich habe ein Programm geschrieben das die PQ Formel lösen soll. An anfang werden P und Q eingelesen und dan Arbeiter das Programm. Die Ergebnise für X1 und X2 die es lösst sind auch richtig. Allerdings setzt es vor die Ausgabe der Ergebnisse immer<br />
0x4375e4<br />
und dann kommt das richtige Ergebnis. Durch ausprobieren bin ich mir Mitlerweile sicher das das Problem beim + bzw. - Rechnen in der Ausgabe Funktion entsteht</p>
<p>Wisst ihr woran das liegen kann</p>
<p>Hier der Quelltext:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;stdlib.h&gt;

using namespace std;

float Wz=0;
float N=1; 
float W=0;
float N1=0;
float N2=0; 
float P=0; 
float Q=0; 
float P2=0; 
float X1=0; 
float X2=0; 

//FUNKTIONEN: 

 //Funktionsprototyp E_PQ 

    void E_PQ (void);

    //Funktionsdefinition E_PQ

    void E_PQ (void)
    {

    cout &lt;&lt;&quot;Bitte geben Sie P ein&quot;; 
    cin  &gt;&gt;P;
    cout &lt;&lt;&quot;Bitte geben Sie Q ein&quot;; 
    cin &gt;&gt;Q; 
    cout &lt;&lt;&quot;\n&quot;; 

    //P/2berechnen.
    P2=P/2; 
    }    

        //Funktionsprototyp B_PQ
        float B_PQ (float, float, float );

        //Funktionsdefinition B_PQ
        float B_PQ(float Wz)
             {

            //PQ_Formel

            //Berechnen Wurzle (alle Zahlen die unter der Wurzel stehen werden zusammengerechnet: 
            Wz=P2*P2-Q;

              do{

              //Wurzel Ziehen so oft bis =Wz ist.
              N1=Wz/N;
              N2=N+N1;
              N=N2/2;

              W=N*N;    
              } while (W&gt;(Wz+0.01));  
               //N ist jetzt der Ausdruck der unter der Wurzel steht 

               cout &lt;&lt;N; 
               cout &lt;&lt;&quot;\n&quot;;
                return N; 
              }      

  //PQ_Ausgabe Prototyp 

  void PQ_Ausgabe (float); 

 //PQ_Ausgabe Definition (N ist der Ausdruck unter der Wurzel) 

 void PQ_Ausgabe (float N)
 {
  cout &lt;&lt; &quot;Vor dem Tausch:\n &quot;;
  cout &lt;&lt; P2; 
  cout &lt;&lt; &quot;\n&quot;; 
  //Forzeichen Tausch 
  P2=P2*-1;

  cout &lt;&lt;&quot;Nach dem Tausch:\n &quot;;
  cout &lt;&lt;P2; 
  cout &lt;&lt;&quot;\n&quot;;

  cout &lt;&lt;&quot;Wurzel nach der Übergabe\n&quot;; 
  cout &lt;&lt;N;
  cout &lt;&lt;&quot;\n&quot;;

  //Hier entsteht das Problem! 
  X1=P2+N;
  X2=P2-N;

  cout &lt;&lt;&quot;X1:&quot; &lt;&lt; cout &lt;&lt;X1; cout &lt;&lt;&quot;\n&quot;;
  cout &lt;&lt;&quot;X2:&quot; &lt;&lt; cout &lt;&lt;X2; cout &lt;&lt;&quot;\n&quot;;

 }     

//HAUPTPROGRAMM

int main(int argc, char *argv[])
{
    //Funktionsaufruf E_PQ (Eingabe) 
    E_PQ(); 

    //Funktionsaufruf B_PQ (Berechnung) 
    N = B_PQ (Wz);

    //Funktionsaufruf PQ_Ausgabe 
    PQ_Ausgabe (N);

  system(&quot;PAUSE&quot;);	
  return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1387073</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1387073</guid><dc:creator><![CDATA[onkel89]]></dc:creator><pubDate>Wed, 17 Oct 2007 11:23:03 GMT</pubDate></item><item><title><![CDATA[Reply to PQ Formel Lösen on Wed, 17 Oct 2007 11:30:31 GMT]]></title><description><![CDATA[<p>Nulltens: Für die Zukunft - sfds (dieses Mal habe ich deinen Beitrag noch angepasst)</p>
<p>Erstens: Globale Variablen sind nie gut - nimm lieber Parameter, um Informationen zwischen den einzelnen Funktionen auszutauschen. (und auch sonst ist es ein Krampf, deinen Quelltext zu lesen)</p>
<p>Zweitens: <code>cout &lt;&lt;&quot;X1:&quot; &lt;&lt; cout &lt;&lt;X1; cout &lt;&lt;&quot;\n&quot;;</code> - in der Zeile ist eindeutig ein 'cout' überflüssig - versuch's mal mit 'cout&lt;&lt;&quot;X1:&quot;&lt;&lt;X1&lt;&lt;endl;'.</p>
<p>Drittens: Hast du auch bedacht, daß eine quadratische Gleichung nicht immer zwei Lösungen hat?</p>
<p>(PS: übrigens brauchst du die Wurzel nicht von Hand auszurechnen - dazu bietet C++ die Funktion 'sqrt()')</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1387083</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1387083</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Wed, 17 Oct 2007 11:30:31 GMT</pubDate></item><item><title><![CDATA[Reply to PQ Formel Lösen on Wed, 17 Oct 2007 11:50:00 GMT]]></title><description><![CDATA[<p>Mittagspause ...:</p>
<p>Ich habe gerade nichts besseres zu tun, als nachzulesen, was PQ-Formeln sind.</p>
<pre><code class="language-cpp">// pq.cpp
#include &lt;iostream&gt;
#include &lt;cmath&gt;
using namespace std;

// Funktionsprototypen
double ergebnisPQ1(double p, double q);
double ergebnisPQ2(double p, double q);

// Programmeinsprungpunkt
int main(int argc, char** args)
    {
        double p;
        double q;

        // Die Werte für p und q vom Benutzer abfragen
        //  Hinweis: Eingaben werden nicht geprüft!
        cout &lt;&lt; &quot;Bitte geben Sie den Wert fuer p ein: &quot; &lt;&lt; flush;
        cin &gt;&gt; p;
        cout &lt;&lt; &quot;Bitte geben Sie den Wert fuer q ein: &quot; &lt;&lt; flush;
        cin &gt;&gt; q;

        // Ergebnisse für x1 und x2 berechnen und ausgeben
        //  Achtung (diese Vereinfachung geht davon aus, dass zwei
        //  Lösungen bestehen !!!)
        cout &lt;&lt; &quot;\nFuer p = &quot; &lt;&lt; p &lt;&lt; &quot; und q = &quot; &lt;&lt; q
            &lt;&lt; &quot; ist x1 = &quot; &lt;&lt; ergebnisPQ1(p, q)
            &lt;&lt; &quot; und x2 = &quot; &lt;&lt; ergebnisPQ2(p, q) &lt;&lt; &quot;.&quot; &lt;&lt; endl;

        return 0;
    }

double ergebnisPQ1(double p, double q)
    {
        // X1 nach PQ-Formel berechnen und zurückgeben
        double x1 = -p / 2.0 + sqrt( pow(p, 2.0) / 4.0 - q);
        return x1;
    }

double ergebnisPQ2(double p, double q)
    {
        // X2 nach PQ-Formel berechnen und zurückgeben
        double x2 = -p / 2.0 - sqrt( pow(p, 2.0) / 4.0 - q);
        return x2;        
    }
</code></pre>
<p>@OP:<br />
1. Funktionsprototypen zu bezeichnen und direkt im Anschluss die Definition der Funktion zu geben ist überflüssig.</p>
<p>2. Trenne Ein- und Ausgabe von der Logik.</p>
<p>3. (die Anmerkungen von CStoll)</p>
<p>4. Kopiere diesen Code NICHT! Lese und verstehe ihn, danach schmeißt du ihn weg und schreibst deinen Code noch einmal neu.</p>
<p>Hinweis: Der von mir generierte Code erhebt keinen Anspruch auf Richtigkeit. Ich habe ihn lediglich an EINER Aufgabe getestet. Außerdem deckt es nur das Ergebnis mit zwei Lösungen ab.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1387111</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1387111</guid><dc:creator><![CDATA[bwbg]]></dc:creator><pubDate>Wed, 17 Oct 2007 11:50:00 GMT</pubDate></item><item><title><![CDATA[Reply to PQ Formel Lösen on Wed, 17 Oct 2007 11:51:10 GMT]]></title><description><![CDATA[<p>Ja gut danke für anpassen ich kannte das Forum vorher nicht.</p>
<p>Stimmt das war ein cout zu viel, das lösst aber das Problem leider nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1387114</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1387114</guid><dc:creator><![CDATA[onkel89]]></dc:creator><pubDate>Wed, 17 Oct 2007 11:51:10 GMT</pubDate></item><item><title><![CDATA[Reply to PQ Formel Lösen on Wed, 17 Oct 2007 11:55:06 GMT]]></title><description><![CDATA[<p>Oh da haben sich gerade die Postings überschnitten.</p>
<p>Jo Danke für den Code.</p>
<p>Weißt du den warum in meinem Eigeneb (ich weiß der ist nicht das Gelbe von Ei) der fehler auftritt einfach mal aus Intresse</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1387120</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1387120</guid><dc:creator><![CDATA[onkel89]]></dc:creator><pubDate>Wed, 17 Oct 2007 11:55:06 GMT</pubDate></item><item><title><![CDATA[Reply to PQ Formel Lösen on Wed, 17 Oct 2007 12:01:17 GMT]]></title><description><![CDATA[<p>Nein, wo es da hakt, kann ich dir nicht sagen. Es war für mich jetzt wesentlich weniger Aufwand zu lesen, was man mit PQ anstellt und den Code da hinzupfeffern als mich durch deinen Code zu wühlen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>Ich, an Deiner Stelle würde das Ding komplett neu zu schreiben. Da ist wirklich keine Übersicht drin. Diese fehlende Übersicht wurde dir hier sicherlich auch zum Verhängnis.</p>
<p>Kein Beinbruch, kann passieren, gerade am Anfang.</p>
<p>Grüße...</p>
<p>Heiko</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1387129</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1387129</guid><dc:creator><![CDATA[bwbg]]></dc:creator><pubDate>Wed, 17 Oct 2007 12:01:17 GMT</pubDate></item><item><title><![CDATA[Reply to PQ Formel Lösen on Wed, 17 Oct 2007 13:02:53 GMT]]></title><description><![CDATA[<p>Der Ausgabe-Fehler wurde von CStoll schon beschrieben, nämlich bzgl. cout (Punkt Zweitens).<br />
P.S. Warum? Es wird eine Hexadezimalzahl ausgegeben, da du den Wert des Objekts 'cout' selbst ausgibst (Speicheradressen werden so dargestellt).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1387180</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1387180</guid><dc:creator><![CDATA[Th]]></dc:creator><pubDate>Wed, 17 Oct 2007 13:02:53 GMT</pubDate></item><item><title><![CDATA[Reply to PQ Formel Lösen on Wed, 17 Oct 2007 13:32:46 GMT]]></title><description><![CDATA[<p>jaja aber das ändern der Ausgabe hat das Problem nicht gelöst. Ich weiß nicht warum für den Quelltext doch mal aus das siehst du was ich meine</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1387227</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1387227</guid><dc:creator><![CDATA[onkel89]]></dc:creator><pubDate>Wed, 17 Oct 2007 13:32:46 GMT</pubDate></item><item><title><![CDATA[Reply to PQ Formel Lösen on Wed, 17 Oct 2007 13:40:11 GMT]]></title><description><![CDATA[<p>Nur nochmal zum Mitschreiben - wie genau sieht denn das Problem aus? (kryptische Hex-Zahlen sollten jetzt eigentlich nicht mehr kommen, außer du gibst noch irgendwo 'cout' aus - bleibt nur noch die fehlende Fallunterscheidung zur Bestimmung der Lösungsmenge (quadratische Gleichungen haben je nach Vorzeichen der Determinante (bei dir &quot;Wz=P2*P2-q&quot;) null bis zwei reelle Lösungen))</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1387233</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1387233</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Wed, 17 Oct 2007 13:40:11 GMT</pubDate></item><item><title><![CDATA[Reply to PQ Formel Lösen on Thu, 18 Oct 2007 12:27:52 GMT]]></title><description><![CDATA[<p>Ich hab das was du mir mit den couts aufgeschrieben hast flalsch umgesetzt (bin halt noch anfänger) <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="🙂"
    /> . Ich hab das jetzt gerade umgestellt und siehe da es tut.</p>
<p>So vielen danke für die Hilfe und für das Durcharbeiten durch das kleine Prog..</p>
<p>Bin froh das das jetzt läuft aber ich denke ich werde mir das mal zu herzen nehmen und soblad ich Zeit hab das ding nochmal in ordentlich neu schreiben</p>
<p>MFG<br />
Johannes</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1387856</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1387856</guid><dc:creator><![CDATA[onkel89]]></dc:creator><pubDate>Thu, 18 Oct 2007 12:27:52 GMT</pubDate></item></channel></rss>