<?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[Warum ergibt das eine Endlosschleife?]]></title><description><![CDATA[<p>Moin, habe nen kleines Problem. Wenn ich in der zweiten schleife den Eingabe Stream per EOF (im Windows mit STRG+Z) auf false setzen will. Geht er in eine Dauerschleife...</p>
<p>Warum? und wie kann ich es besser machen :)?</p>
<p>Criseas</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &quot;Sales_item.h&quot;
using namespace std;

int main() {
    Sales_item eingabe, item1, item2, item3, item4;
    int count=1;
    while(count==1) 
    {
      cout&lt;&lt;&quot;Geben sie ihre ISBN ein!&quot;&lt;&lt;endl;
      cin&gt;&gt;item1;
      cout&lt;&lt;&quot;next&quot;&lt;&lt;endl;
      while(count&lt;=3) 
      {
        cin&gt;&gt;eingabe
        if(eingabe.same_isbn(item1)) 
        {
          item1 = item1 + eingabe;
          cout&lt;&lt;&quot;next&quot;&lt;&lt;endl;
          count++; 
        } else {
          cout&lt;&lt;&quot;Ungültige eingabe!&quot;&lt;&lt;endl; 
        }
      }
      cout&lt;&lt;count&lt;&lt;&quot; Transaktionen: &quot;&lt;&lt;item1&lt;&lt;endl;
      cout&lt;&lt;&quot;1. Weiter | 2. Abbruch&quot;&lt;&lt;endl;
      cin&gt;&gt;count;
      if(count!=1) {
                 return 0;
                 } 
      return 0;
    }
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/262036/warum-ergibt-das-eine-endlosschleife</link><generator>RSS for Node</generator><lastBuildDate>Sun, 06 Sep 2026 21:48:41 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/262036.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 27 Feb 2010 16:43:45 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Warum ergibt das eine Endlosschleife? on Sat, 27 Feb 2010 16:43:45 GMT]]></title><description><![CDATA[<p>Moin, habe nen kleines Problem. Wenn ich in der zweiten schleife den Eingabe Stream per EOF (im Windows mit STRG+Z) auf false setzen will. Geht er in eine Dauerschleife...</p>
<p>Warum? und wie kann ich es besser machen :)?</p>
<p>Criseas</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &quot;Sales_item.h&quot;
using namespace std;

int main() {
    Sales_item eingabe, item1, item2, item3, item4;
    int count=1;
    while(count==1) 
    {
      cout&lt;&lt;&quot;Geben sie ihre ISBN ein!&quot;&lt;&lt;endl;
      cin&gt;&gt;item1;
      cout&lt;&lt;&quot;next&quot;&lt;&lt;endl;
      while(count&lt;=3) 
      {
        cin&gt;&gt;eingabe
        if(eingabe.same_isbn(item1)) 
        {
          item1 = item1 + eingabe;
          cout&lt;&lt;&quot;next&quot;&lt;&lt;endl;
          count++; 
        } else {
          cout&lt;&lt;&quot;Ungültige eingabe!&quot;&lt;&lt;endl; 
        }
      }
      cout&lt;&lt;count&lt;&lt;&quot; Transaktionen: &quot;&lt;&lt;item1&lt;&lt;endl;
      cout&lt;&lt;&quot;1. Weiter | 2. Abbruch&quot;&lt;&lt;endl;
      cin&gt;&gt;count;
      if(count!=1) {
                 return 0;
                 } 
      return 0;
    }
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1862117</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1862117</guid><dc:creator><![CDATA[Criseas]]></dc:creator><pubDate>Sat, 27 Feb 2010 16:43:45 GMT</pubDate></item><item><title><![CDATA[Reply to Warum ergibt das eine Endlosschleife? on Sat, 27 Feb 2010 16:47:27 GMT]]></title><description><![CDATA[<p>Du solltest irgendwo den Status des Eingabestreams abfragen und ggf. die Schleife verlassen.</p>
<pre><code class="language-cpp">if (!cin)
  return;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1862119</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1862119</guid><dc:creator><![CDATA[blubb]]></dc:creator><pubDate>Sat, 27 Feb 2010 16:47:27 GMT</pubDate></item><item><title><![CDATA[Reply to Warum ergibt das eine Endlosschleife? on Sat, 27 Feb 2010 16:54:14 GMT]]></title><description><![CDATA[<p>Noch als Ergaenzung und Antwort auf das 'Warum':<br />
Weil die IO-Streams, wenn in einem Fehlerzustand (wozu auch EOF zaehlt), einfach nichts machen, d.h. weder einen Wert lesen noch den uebergebenen Wert veraendern.</p>
<pre><code class="language-cpp">while(count&lt;=3) 
      {
        cin&gt;&gt;eingabe
        if(eingabe.same_isbn(item1)) 
        {
          item1 = item1 + eingabe;
          cout&lt;&lt;&quot;next&quot;&lt;&lt;endl;
          count++; 
        } else {
          cout&lt;&lt;&quot;Ungültige eingabe!&quot;&lt;&lt;endl; 
        }
      }
</code></pre>
<p>Hier kann z.B. eine Endlosschleife entstehen, wenn !cin.good - in dem Fall wird ggf. count nie veraendert (weil eingabe.same_isbn(item1) ggf. nie erfuellt).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1862120</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1862120</guid><dc:creator><![CDATA[blubb]]></dc:creator><pubDate>Sat, 27 Feb 2010 16:54:14 GMT</pubDate></item><item><title><![CDATA[Reply to Warum ergibt das eine Endlosschleife? on Sun, 28 Feb 2010 22:41:31 GMT]]></title><description><![CDATA[<p>Hey danke dir für deine Antworten.</p>
<p>Tut mir leid mir ist gerade aufgefallen das ich den falschen Quelltext gepostet habe.<br />
Hatte 2 Versionen und hab natürlich den falschen erwischt...<br />
Es ist nur ein kleiner unterschied bei der zweiten schleife...<br />
Aber gleiche Frage wie oben^^.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &quot;Sales_item.h&quot;
using namespace std;

int main() {
    Sales_item eingabe, item1, item2, item3, item4;
    int count=1;
    while(count==1) 
    {
      cout&lt;&lt;&quot;Geben sie ihre ISBN ein!&quot;&lt;&lt;endl;
      cin&gt;&gt;item1;
      cout&lt;&lt;&quot;next&quot;&lt;&lt;endl;
      while(cin&gt;&gt;eingabe) 
      {
        if(eingabe.same_isbn(item1)) 
        {
          item1 = item1 + eingabe;
          cout&lt;&lt;&quot;next&quot;&lt;&lt;endl;
          count++; 
        } else {
          cout&lt;&lt;&quot;Ungültige eingabe!&quot;&lt;&lt;endl; 
        }
      }
      cout&lt;&lt;count&lt;&lt;&quot; Transaktionen: &quot;&lt;&lt;item1&lt;&lt;endl;
      cout&lt;&lt;&quot;1. Weiter | 2. Abbruch&quot;&lt;&lt;endl;
      cin&gt;&gt;count;
      if(count!=1) {
                 return 0;
                 } 
      return 0;
    }
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1862497</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1862497</guid><dc:creator><![CDATA[Criseas]]></dc:creator><pubDate>Sun, 28 Feb 2010 22:41:31 GMT</pubDate></item><item><title><![CDATA[Reply to Warum ergibt das eine Endlosschleife? on Sun, 28 Feb 2010 23:16:44 GMT]]></title><description><![CDATA[<blockquote>
<p>Aber gleiche Frage wie oben^^.</p>
</blockquote>
<p>Gleiche Antwort wie oben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1862505</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1862505</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Sun, 28 Feb 2010 23:16:44 GMT</pubDate></item><item><title><![CDATA[Reply to Warum ergibt das eine Endlosschleife? on Sun, 28 Feb 2010 23:20:39 GMT]]></title><description><![CDATA[<p>Okey aber wenn ich in der While(cin&gt;&gt;variable)</p>
<p>hab und ich des mit strg+z abbreche.. müsste es doch weiterlaufen bis zu der eingabe wo ich das Programm beenden oder Weiterlaufen müsste... oder seh ich das falsch?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1862506</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1862506</guid><dc:creator><![CDATA[Criseas]]></dc:creator><pubDate>Sun, 28 Feb 2010 23:20:39 GMT</pubDate></item><item><title><![CDATA[Reply to Warum ergibt das eine Endlosschleife? on Mon, 01 Mar 2010 06:10:40 GMT]]></title><description><![CDATA[<p>Allgemein versteh ich auch nicht so ganz was du da veranstaltest. Du hast 4 Items und eine Eingabe, dann lässt du den Benutzer eine ISBN eingeben, die unter item1 abgespeichert wird. Dann lässt du den Benutzer nochmal eine ISBN eingeben, die unter eingabe gespeichert wird und prüfst über eine Funktion, ob diese gleich sind (wie wärs wenn du den == Gleichheitsoperator überlädst?) und wenn sie gleich sind, dann verbindest du item1 mit der eingabe (ich hoffe du hast den + Operator überladen). Was macht das für einen Sinn? Du verbindest sie nur wenn beide gleich sind und wenn nicht, ist die Eingabe ungültig.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1862532</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1862532</guid><dc:creator><![CDATA[freaky]]></dc:creator><pubDate>Mon, 01 Mar 2010 06:10:40 GMT</pubDate></item><item><title><![CDATA[Reply to Warum ergibt das eine Endlosschleife? on Mon, 01 Mar 2010 06:11:33 GMT]]></title><description><![CDATA[<p>[OT]<br />
<a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/19847">@FreakY</a>&lt;3Cpp<br />
Du alter freak, sag nicht du gehst morgens vor der Schule noch ins Forum <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 />
[/OT]</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1862533</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1862533</guid><dc:creator><![CDATA[Kóyaánasqatsi]]></dc:creator><pubDate>Mon, 01 Mar 2010 06:11:33 GMT</pubDate></item><item><title><![CDATA[Reply to Warum ergibt das eine Endlosschleife? on Mon, 01 Mar 2010 06:13:05 GMT]]></title><description><![CDATA[<p>Kóyaánasqatsi schrieb:</p>
<blockquote>
<p>[OT]<br />
<a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/19847">@FreakY</a>&lt;3Cpp<br />
Du alter freak, sag nicht du gehst morgens vor der Schule noch ins Forum <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 />
[/OT]</p>
</blockquote>
<p>DU alter freak :p ...<br />
Naja die verdammten Züge meinen nicht zu fahren. Jetzt muss ich erst mal gleich zur Schule gefahren werden und weil was wichtiges ist, muss ich da auch noch hin. Ansonsten würde ich wieder im Bett liegen und von Sachen träumen, was genau, will ich jetzt nicht weiter erläutern.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1862534</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1862534</guid><dc:creator><![CDATA[freaky]]></dc:creator><pubDate>Mon, 01 Mar 2010 06:13:05 GMT</pubDate></item><item><title><![CDATA[Reply to Warum ergibt das eine Endlosschleife? on Mon, 01 Mar 2010 10:05:42 GMT]]></title><description><![CDATA[<p>Criseas schrieb:</p>
<blockquote>
<p>Okey aber wenn ich in der While(cin&gt;&gt;variable)</p>
<p>hab und ich des mit strg+z abbreche.. müsste es doch weiterlaufen bis zu der eingabe wo ich das Programm beenden oder Weiterlaufen müsste... oder seh ich das falsch?</p>
</blockquote>
<p>Haste eigentlich Recht, war gestern ein bisschen spät, als ich geantwortet habe <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="🙄"
    /> . Kannst du mal deinen Operator &gt;&gt; zeigen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1862573</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1862573</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Mon, 01 Mar 2010 10:05:42 GMT</pubDate></item><item><title><![CDATA[Reply to Warum ergibt das eine Endlosschleife? on Tue, 02 Mar 2010 12:46:18 GMT]]></title><description><![CDATA[<p>Hmm okey schon, ich weiß das ich das mit counter oder einer eindeutigen Bedingungen machen könnte.</p>
<p>Aber es geht ja auch das die While solange läuft wie man eingaben tätigt.. Jedenfalls steht es so im C++ Primer</p>
<pre><code class="language-cpp">while(cin&gt;&gt;eingabe)
</code></pre>
<p>Und das durch ein EOF die While unterbrochen wird.</p>
<p>Allerdings gerate ich dadurch wie oben geschrieben in eine Dauerschleife.. und ich versteh nicht warum.</p>
<p>Die Variablen item2-4 kann man vergessen die sind noch nicht deklariert.</p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/19375">@SeppJ</a> das ist &quot;eingabe&quot;</p>
<p>Viele Grüße</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1863273</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1863273</guid><dc:creator><![CDATA[Criseas]]></dc:creator><pubDate>Tue, 02 Mar 2010 12:46:18 GMT</pubDate></item><item><title><![CDATA[Reply to Warum ergibt das eine Endlosschleife? on Tue, 02 Mar 2010 15:01:00 GMT]]></title><description><![CDATA[<p>Criseas schrieb:</p>
<blockquote>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/19375">@SeppJ</a> das ist &quot;eingabe&quot;</p>
</blockquote>
<p>???????????????????</p>
<p>Der Sepp hat dich gebeten den &gt;&gt;Operator für die Klasse Sales_item herzuzeigen.</p>
<p>Es sieht im Moment so aus, als wurde für die Klasse Sales_item der &gt;&gt;Operator überladen. Um dir helfen zu können müsste man daher wissen, was dort gemacht wird.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1863347</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1863347</guid><dc:creator><![CDATA[hmpf]]></dc:creator><pubDate>Tue, 02 Mar 2010 15:01:00 GMT</pubDate></item><item><title><![CDATA[Reply to Warum ergibt das eine Endlosschleife? on Tue, 02 Mar 2010 15:19:31 GMT]]></title><description><![CDATA[<p>Achsoo,<br />
ja sorry bin noch nicht soweit in der Materie, in dem Buch sind die mir Bekannten Operationen von der Klasse das Addieren von Sales_item objekten. Sowie das Vergleichen von 2 ISBNs mittels variable.same_isbn(variable) als Elementfunktion sowie das lesen und schreiben sowie zuweisen mit cin und cout und =.</p>
<p>Mehr ist mir von der Klasse noch nicht bekannt.<br />
Wenn ihr mir sagt was ich euch nun genau zeigen soll kann ich das tun. So versteh ich aber nicht was ihr mit Überladen meint.</p>
<p>Danke euch soweit schonmal^^</p>
<p>Grüße</p>
<p>Criseas</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1863364</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1863364</guid><dc:creator><![CDATA[Criseas]]></dc:creator><pubDate>Tue, 02 Mar 2010 15:19:31 GMT</pubDate></item><item><title><![CDATA[Reply to Warum ergibt das eine Endlosschleife? on Tue, 02 Mar 2010 15:31:16 GMT]]></title><description><![CDATA[<p>Irgendwo, vermutlich in einer Datei namens sales_item.cpp oder so ähnlich, gibt es sowas in der Art:</p>
<pre><code class="language-cpp">std::ostream&amp; operator&lt;&lt;(std::ostream&amp; lhs, Sales_item const&amp; rhs) // Genaue Syntax und Variablennamen können anders sein
{
 // Und das was hier steht, müssen wir wissen um dir zu helfen
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1863369</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1863369</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Tue, 02 Mar 2010 15:31:16 GMT</pubDate></item><item><title><![CDATA[Reply to Warum ergibt das eine Endlosschleife? on Tue, 02 Mar 2010 15:35:19 GMT]]></title><description><![CDATA[<p>Was Sepp wohl meint ist</p>
<pre><code class="language-cpp">istream&amp; operator&gt;&gt;(istream&amp;, Sales_item&amp;);
</code></pre>
<p>Also, Eingabe und nicht Ausgabe.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1863371</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1863371</guid><dc:creator><![CDATA[hmpf]]></dc:creator><pubDate>Tue, 02 Mar 2010 15:35:19 GMT</pubDate></item><item><title><![CDATA[Reply to Warum ergibt das eine Endlosschleife? on Tue, 02 Mar 2010 15:38:05 GMT]]></title><description><![CDATA[<p>hmpf schrieb:</p>
<blockquote>
<p>Was Sepp wohl meint ist</p>
<pre><code class="language-cpp">istream&amp; operator&gt;&gt;(istream&amp;, Sales_item&amp;);
</code></pre>
<p>Also, Eingabe und nicht Ausgabe.</p>
</blockquote>
<p>Ähh, ja, bin gerade durcheinander gekommen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1863375</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1863375</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Tue, 02 Mar 2010 15:38:05 GMT</pubDate></item><item><title><![CDATA[Reply to Warum ergibt das eine Endlosschleife? on Tue, 02 Mar 2010 15:40:10 GMT]]></title><description><![CDATA[<p>So ich hoffe ich darf das posten ansonsten sagt mir bescheid dann lösch ich das wieder :).</p>
<pre><code class="language-cpp">/*
 * This file contains code from &quot;C++ Primer, Fourth Edition&quot;, by Stanley B.
 * Lippman, Jose Lajoie, and Barbara E. Moo, and is covered under the
 * copyright and warranty notices given in that book:
 * 
 * &quot;Copyright (c) 2005 by Objectwrite, Inc., Jose Lajoie, and Barbara E. Moo.&quot;
 * 
 * 
 * &quot;The authors and publisher have taken care in the preparation of this book,
 * but make no expressed or implied warranty of any kind and assume no
 * responsibility for errors or omissions. No liability is assumed for
 * incidental or consequential damages in connection with or arising out of the
 * use of the information or programs contained herein.&quot;
 * 
 * Permission is granted for this code to be used for educational purposes in
 * association with the book, given proper citation if and when posted or
 * reproduced.Any commercial use of this code requires the explicit written
 * permission of the publisher, Addison-Wesley Professional, a division of
 * Pearson Education, Inc. Send your request for permission, stating clearly
 * what code you would like to use, and in what specific way, to the following
 * address: 
 * 
 * 	Pearson Education, Inc.
 * 	Rights and Contracts Department
 * 	75 Arlington Street, Suite 300
 * 	Boston, MA 02216
 * 	Fax: (617) 848-7047
*/ 

#ifndef SALESITEM_H
#define SALESITEM_H

// Definition of Sales_item class and related functions goes here

#include &lt;iostream&gt;
#include &lt;string&gt;

class Sales_item {
friend bool operator==(const Sales_item&amp;, const Sales_item&amp;);
// other members as before
public:
    // added constructors to initialize from a string or an istream
    Sales_item(const std::string &amp;book):
              isbn(book), units_sold(0), revenue(0.0) { }
    Sales_item(std::istream &amp;is) { is &gt;&gt; *this; }
    friend std::istream&amp; operator&gt;&gt;(std::istream&amp;, Sales_item&amp;);
    friend std::ostream&amp; operator&lt;&lt;(std::ostream&amp;, const Sales_item&amp;);
public:
    // operations on Sales_item objects
    // member binary operator: left-hand operand bound to implicit this pointer
    Sales_item&amp; operator+=(const Sales_item&amp;);
    // other members as before

public:
    // operations on Sales_item objects
    double avg_price() const;
    bool same_isbn(const Sales_item &amp;rhs) const
        { return isbn == rhs.isbn; }
    // default constructor needed to initialize members of built-in type
    Sales_item(): units_sold(0), revenue(0.0) { }
// private members as before
private:
    std::string isbn;
    unsigned units_sold;
    double revenue;

};

// nonmember binary operator: must declare a parameter for each operand
Sales_item operator+(const Sales_item&amp;, const Sales_item&amp;);

inline bool 
operator==(const Sales_item &amp;lhs, const Sales_item &amp;rhs)
{
    // must be made a friend of Sales_item
    return lhs.units_sold == rhs.units_sold &amp;&amp;
           lhs.revenue == rhs.revenue &amp;&amp;
	   lhs.same_isbn(rhs);
}

inline bool 
operator!=(const Sales_item &amp;lhs, const Sales_item &amp;rhs)
{
    return !(lhs == rhs); // != defined in terms of operator==
}

using std::istream; using std::ostream;

// assumes that both objects refer to the same isbn
inline
Sales_item&amp; Sales_item::operator+=(const Sales_item&amp; rhs) 
{
    units_sold += rhs.units_sold; 
    revenue += rhs.revenue; 
    return *this;
}

// assumes that both objects refer to the same isbn
inline
Sales_item 
operator+(const Sales_item&amp; lhs, const Sales_item&amp; rhs) 
{
    Sales_item ret(lhs);  // copy lhs into a local object that we'll return
    ret += rhs;           // add in the contents of rhs 
    return ret;           // return ret by value
}

inline
istream&amp; 
operator&gt;&gt;(istream&amp; in, Sales_item&amp; s)
{
    double price;
    in &gt;&gt; s.isbn &gt;&gt; s.units_sold &gt;&gt; price;
    // check that the inputs succeeded
    if (in)
        s.revenue = s.units_sold * price;
    else 
        s = Sales_item();  // input failed: reset object to default state
    return in;
}

inline
ostream&amp; 
operator&lt;&lt;(ostream&amp; out, const Sales_item&amp; s)
{
    out &lt;&lt; s.isbn &lt;&lt; &quot;\t&quot; &lt;&lt; s.units_sold &lt;&lt; &quot;\t&quot; 
        &lt;&lt; s.revenue &lt;&lt; &quot;\t&quot; &lt;&lt;  s.avg_price();
    return out;
}

inline
double Sales_item::avg_price() const
{
    if (units_sold) 
        return revenue/units_sold; 
    else 
        return 0;
}

#endif
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1863379</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1863379</guid><dc:creator><![CDATA[Criseas]]></dc:creator><pubDate>Tue, 02 Mar 2010 15:40:10 GMT</pubDate></item><item><title><![CDATA[Reply to Warum ergibt das eine Endlosschleife? on Tue, 02 Mar 2010 15:52:28 GMT]]></title><description><![CDATA[<p>Nie im Leben gibt das eine Endlosschleife. Ist das ganz sicher der richtige Code? Mit allen Klammern <strong>exakt</strong> so wie hier geschrieben?</p>
<pre><code class="language-cpp">while(count==1)
    {
      cout&lt;&lt;&quot;Geben sie ihre ISBN ein!&quot;&lt;&lt;endl;
      cin&gt;&gt;item1;
      cout&lt;&lt;&quot;next&quot;&lt;&lt;endl;
      while(cin&gt;&gt;eingabe)
      {
        if(eingabe.same_isbn(item1))
        {
          item1 = item1 + eingabe;
          cout&lt;&lt;&quot;next&quot;&lt;&lt;endl;
          count++;
        } else {
          cout&lt;&lt;&quot;Ungültige eingabe!&quot;&lt;&lt;endl;
        }
      }
      cout&lt;&lt;count&lt;&lt;&quot; Transaktionen: &quot;&lt;&lt;item1&lt;&lt;endl;
      cout&lt;&lt;&quot;1. Weiter | 2. Abbruch&quot;&lt;&lt;endl;
      cin&gt;&gt;count;
      if(count!=1) {
                 return 0;
                 }
      return 0;
    }
</code></pre>
<p>Wie sieht denn die Ausgabe aus?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1863384</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1863384</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Tue, 02 Mar 2010 15:52:28 GMT</pubDate></item><item><title><![CDATA[Reply to Warum ergibt das eine Endlosschleife? on Tue, 02 Mar 2010 16:00:51 GMT]]></title><description><![CDATA[<p>SeppJ schrieb:</p>
<blockquote>
<p>Nie im Leben gibt das eine Endlosschleife. ...</p>
</blockquote>
<p>Sehe ich auch so. Im Gegenteil durch das return 0 innerhalb der while (count==1) Schleife ist man sogar früher als geplant aus dem Programm heraus.</p>
<p>Der hier präsentierte Quelltext stimmt wohl nicht mit dem überein, was der Fragesteller daheim ausführt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1863390</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1863390</guid><dc:creator><![CDATA[hmpf]]></dc:creator><pubDate>Tue, 02 Mar 2010 16:00:51 GMT</pubDate></item><item><title><![CDATA[Reply to Warum ergibt das eine Endlosschleife? on Tue, 02 Mar 2010 16:11:17 GMT]]></title><description><![CDATA[<p>Die Ausgabe sieht wie folgt aus:</p>
<blockquote>
<p>F:\Salesitem2.exe<br />
Geben sie ihre ISBN ein!<br />
0-201-78345-x 5 50.00<br />
next<br />
0-201-78345-x 3 25.00<br />
next<br />
0-202-78343-x 2 20.00<br />
Ung³ltige eingabe!<br />
0-201-78345-x 3 25.00<br />
next<br />
^Z<br />
3 Transaktionen: 0-201-78345-x 11 400 36.3636<br />
1. Weiter | 2. Abbruch</p>
<p>F:\</p>
</blockquote>
<p>wie mann nach<br />
1. Weiter | 2. Abbruch</p>
<p>sehen kann konnte ich nixmehr eingeben!</p>
<p>Aber durch eine Änderung weiter oben nehmlich</p>
<pre><code class="language-cpp">cout&lt;&lt;&quot;Geben sie ihre ISBN ein!&quot;&lt;&lt;endl;
      cin&gt;&gt;item1;
      cout&lt;&lt;&quot;next&quot;&lt;&lt;endl;
      while(cin&gt;&gt;eingabe)
</code></pre>
<p>geht es auch nichtmehr in eine Dauerschleife und ich weiß warum!! AHA</p>
<p>Die Frage ist nun geklärt. Aber warum Funktioniert es nicht so wie gewünscht? Also warum kann ich vor der IF den Eingabestream nicht benutzen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1863393</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1863393</guid><dc:creator><![CDATA[Criseas]]></dc:creator><pubDate>Tue, 02 Mar 2010 16:11:17 GMT</pubDate></item><item><title><![CDATA[Reply to Warum ergibt das eine Endlosschleife? on Tue, 02 Mar 2010 16:13:59 GMT]]></title><description><![CDATA[<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f621.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--pouting_face"
      title=":rage:"
      alt="😡"
    /> Dann war die frage die ganze Zeit, warum das <strong>keine</strong> Endlosschleife ergibt? Na vielen Dank, das hätten wir dir auch sofort beantworten können. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f621.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--pouting_face"
      title=":rage:"
      alt="😡"
    /></p>
<p>Criseas schrieb:</p>
<blockquote>
<p>Die Frage ist nun geklärt. Aber warum Funktioniert es nicht so wie gewünscht?</p>
</blockquote>
<p>Um es mal direkt zu sagen: Weil dein Code ein totales Schlamassel ist. FreakY&lt;3Cpp hat schon ein paar passende Bemerkungen gemacht. Dein Einsatz der Kontrollstrukturen ist total wirr und sinnlos. Schmeiss den ganzen Code weg. Mach dir erstmal Gedanken, wie dein Programm ablaufen soll. Das malst du dir dann auf einem Blatt Papier als Ablaufplan hin. Und diesen Plan übersetzt du dann in C++ Kontrollstrukturen. Und dann wird das auch funktionieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1863404</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1863404</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Tue, 02 Mar 2010 16:13:59 GMT</pubDate></item><item><title><![CDATA[Reply to Warum ergibt das eine Endlosschleife? on Tue, 02 Mar 2010 16:23:23 GMT]]></title><description><![CDATA[<p>Auch wenn ich jetzt das Bedürfnis verspüre eine Made zu zerquetschen, würde ich nicht so weit gehen wie der Sepp.</p>
<p>Die Schleife while(count==1) bricht auf jeden Fall ab, weil du das zweite return 0 innerhalb dieser Schleife positioniert hast und nicht kurz vor Ende der main() wo es vermutlich hin soll.</p>
<p>Und das cin kannst du vor dem if nicht so einfach verwenden, weil durch den Abbruch mit STRG-Z das Objekt cin noch immer in einem Fehlerzustand ist. Du müsstest also den Puffer leeren und den Fehlerzustand beseitigen. Dann kannst du damit die Variable count einlesen.</p>
<p>Ansonsten ist dein Programm ganz OK und wird wohl auch tun, was du geplant hast.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1863412</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1863412</guid><dc:creator><![CDATA[hmpf]]></dc:creator><pubDate>Tue, 02 Mar 2010 16:23:23 GMT</pubDate></item><item><title><![CDATA[Reply to Warum ergibt das eine Endlosschleife? on Tue, 02 Mar 2010 16:31:41 GMT]]></title><description><![CDATA[<p>Nein, SeppJ hat Recht, der Code ist Müll und macht überhaupt keinen Sinn.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1863418</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1863418</guid><dc:creator><![CDATA[freaky]]></dc:creator><pubDate>Tue, 02 Mar 2010 16:31:41 GMT</pubDate></item><item><title><![CDATA[Reply to Warum ergibt das eine Endlosschleife? on Tue, 02 Mar 2010 17:03:31 GMT]]></title><description><![CDATA[<p>FreakY&lt;3Cpp schrieb:</p>
<blockquote>
<p>Nein, SeppJ hat Recht, der Code ist Müll und macht überhaupt keinen Sinn.</p>
</blockquote>
<p>Dem kann ich nicht zustimmen.</p>
<p>Die Kontrollstrukturen sind absolut OK und hätten ohne die allgemeine Vewirrung/Schwierigkeit mit cin wunderbar gearbeitet.</p>
<p>Als nächstes wird der Fragesteller wohl merken, dass er mit item1, item2, item3 nicht ganz das erreicht was er plant und sich z.B. mit Arrays beschäftigen.</p>
<p>Programmiertechnisch ist das also schon OK und absolut im Rahmen des Weges den ein Programmieranfänger nun mal gehen muss.</p>
<p>Ich denke gerade DU kannst dich gut in diese Lage hineinversetzen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1863435</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1863435</guid><dc:creator><![CDATA[hmpf]]></dc:creator><pubDate>Tue, 02 Mar 2010 17:03:31 GMT</pubDate></item><item><title><![CDATA[Reply to Warum ergibt das eine Endlosschleife? on Tue, 02 Mar 2010 17:13:41 GMT]]></title><description><![CDATA[<p>Danke euch leute^^,</p>
<p>Etwas zu meiner Verteidigung.</p>
<p>Anfangs war es wirklich so das eine Dauerschleife kam. Allerdings habe ich den Fehler irgendwann gefunden, und später ja die andere Version mit dem cin in der While Schleife gepostet. Da hat ich das Problem vergessen neu zu Definieren.</p>
<p>Danke dir Hmpf für die Verteidigung :). Das Programm tut eigtl schon was es soll nur Hmpf hat mir gerade den Fehler genannt den ich hatte.</p>
<p>Der Puffer muss geleert werden... das kann ich mit cout tun soweit ich weiß!? Allerdings möcht ich das ja ungern ausgeben, gibt es noch eine andere möglichkeit den Puffer zu leeren sodas ich cin wieder verwenden kann?</p>
<p>Wie muss ich das mit dem Puffer eigtl genau verstehen, das wurde im Buch noch nicht erläutert, denn ich kann die ganze Zeit Daten eingeben ohne das soetwas passiert?</p>
<p>Danke schonmal^^</p>
<p>Grüße<br />
Criseas</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1863443</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1863443</guid><dc:creator><![CDATA[Criseas]]></dc:creator><pubDate>Tue, 02 Mar 2010 17:13:41 GMT</pubDate></item><item><title><![CDATA[Reply to Warum ergibt das eine Endlosschleife? on Tue, 02 Mar 2010 17:35:50 GMT]]></title><description><![CDATA[<p>Was redest du immer von Kontrollstrukturen? Ich red garnicht von der Klasse, sondern von der main, die Logik fehlt dort doch total.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1863454</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1863454</guid><dc:creator><![CDATA[freaky]]></dc:creator><pubDate>Tue, 02 Mar 2010 17:35:50 GMT</pubDate></item></channel></rss>