<?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[Doppelte Ausgabe in else if Abfragen wegen Objekt?]]></title><description><![CDATA[<p>Hallo Leute,<br />
Ich bin gerade dabei C++ zu lernen und hab mich heute an der Objektorientierung versucht.<br />
Alles klappt eigentlich, bis auf den Fall, dass in der Funktion calc eine doppelte Abfrage der Nachricht in cout kommt bis das Ergebnis ausgegeben wird.</p>
<pre><code>#include &lt;iostream&gt;
#include &quot;badgeCalc.h&quot;
using namespace std;

int main()
{

BadgeCalc b;

b.dialog();
b.eingabe(b);
b.calc(b);
b.result(b);

cout &lt;&lt;&quot;jahre: &quot; &lt;&lt; b.getYears() &lt;&lt; &quot;\n&quot;;
cout &lt;&lt; &quot;Ausbildung: &quot; &lt;&lt; b.getAusbildung() &lt;&lt; '\n';

}
</code></pre>
<pre><code>#include &lt;iostream&gt;
#include &quot;badgeCalc.h&quot;

using namespace std;

const int BadgeCalc::getYears()const{
    return years;
    }

const int BadgeCalc::getAusbildung()const{
    return ausbildung;
    }

void BadgeCalc::dialog ()const{

    cout &lt;&lt; &quot;Bitte geben Sie die Dienstjahre ein: \n&quot;;
    cout &lt;&lt; &quot;Bitte wählen Sie die passende Zahl zum höchsten Ausbildungsstand: \n&quot;;
    cout &lt;&lt; &quot;0:Keine Ausbildung \n&quot; &lt;&lt; &quot;1: Grundausbildung \n&quot; &lt;&lt; &quot;2: Sprechfunker,Atemschutz,Maschinist \n&quot;&lt;&lt; &quot;3: Truppfuehrer \n&quot; &lt;&lt; &quot;4: Gruppenfuehrer \n&quot;
         &lt;&lt; &quot;5: Ausbilder \n&quot; &lt;&lt; &quot;6: Zugfuehrer \n&quot;&lt;&lt; &quot;7: Verbandsfuehrer \n&quot;;

}

void BadgeCalc::setYears(int y){

years = y;
}

void BadgeCalc::setAusbildung(int c){

ausbildung = c;

}

const int BadgeCalc::eingabe(BadgeCalc&amp; b){

    int years;
    int c;

    cin &gt;&gt; years;
    cin &gt;&gt; c;
    b.setYears(years);
    b.setAusbildung(c);

}

int BadgeCalc::calc(BadgeCalc&amp; b){
    int gf;
    int y = b.years;
    char c = b.ausbildung;

    if(y == 0){
        return 0;
        }
    else if(y&gt;0  &amp;&amp; (c == 1) &amp;&amp; y &lt; 11){
        return 1;

        }

    else if(y &gt;= 11 &amp;&amp; c &lt; 4|| (y &gt;= 4 &amp;&amp; c == 2)){
        return 2;

        }

    else if(y &gt;= 21 &amp;&amp; c &lt; 4 || (y &gt;= 16 &amp;&amp; c == 3) || (y &gt;= 9 &amp;&amp; c == 3)){
        return 3;

        }
    else if(y &gt;= 1 &amp;&amp; c == 4){
        int gf;
        cout &lt;&lt; &quot;Seit wann ist die die Person GF?: \n&quot;; // Diese Abfrage erscheint dppelt
        cin &gt;&gt; gf;
        if(gf &lt;10 ){
            return 4;
            }
        else if(gf &gt;= 15){
            return 6;
            }
        else{
            return 5;
        }
        }
    else if(y &gt;= 1 &amp;&amp; c == 5){

        cout &lt;&lt; &quot;Seit wann ist die Person GF?: &quot;; // Diese Abfrage erscheint dppelt
        cin &gt;&gt; gf;
        if(gf &lt;5 ){
            return 4;
            }
        else if(gf &gt;= 10){
            return 6;
            }
        else {
            return 5;
            }
        }
    else if(y &gt;= 1 &amp;&amp; c == 6){
        int zf;
        cout &lt;&lt; &quot;Seit wann ist die Person ZF: &quot;; // Diese Abfrage erscheint dppelt
        cin &gt;&gt; zf;
        if(zf &lt; 10){
            return 7; }

        else if(zf &gt;= 20){
            return 9;
            }
        else {
        return 8;
        }
      }
    else if(y &gt;= 1 &amp;&amp; c == 7){
        int zf;
        cout &lt;&lt; &quot;Seit wann ist die Person ZF: &quot;;
        cin &gt;&gt; zf;
        if(zf &lt; 5){
            return 7;
            }
        else if(zf &gt;= 15){
            return 9;
            }
        else{
            return 8;
            }
        }
    else {cout &lt;&lt; &quot;Fehlerhafte Eingabe!&quot;;
        }

}

const void BadgeCalc::result(BadgeCalc&amp; b){
    int res = b.calc(b);
    cout &lt;&lt; &quot;Abzeichen Nummer: &quot; &lt;&lt; res &lt;&lt; '\n';

}
</code></pre>
<pre><code>#ifndef BADGECALC_H_INCLUDED
#define BADGECALC_H_INCLUDED

class BadgeCalc{

public:

    const int getYears()const;
    const int getAusbildung()const;
    void setYears(int years);
    void setAusbildung(int ausbildung);
    void dialog()const;
    int calc(BadgeCalc&amp; b);
    const int eingabe(BadgeCalc&amp; b);
    const void result(BadgeCalc&amp; b);

private:

int years;
int ausbildung;

};

#endif
</code></pre>
<p>Falls mir jemand weiterhelfen kann würde ich mich sehr über eine Rückmeldung freuen <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="🙂"
    /></p>
<p>LG<br />
Marci</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/337039/doppelte-ausgabe-in-else-if-abfragen-wegen-objekt</link><generator>RSS for Node</generator><lastBuildDate>Sat, 18 Apr 2026 13:31:13 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/337039.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 03 Mar 2016 18:01:28 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Doppelte Ausgabe in else if Abfragen wegen Objekt? on Thu, 03 Mar 2016 18:01:28 GMT]]></title><description><![CDATA[<p>Hallo Leute,<br />
Ich bin gerade dabei C++ zu lernen und hab mich heute an der Objektorientierung versucht.<br />
Alles klappt eigentlich, bis auf den Fall, dass in der Funktion calc eine doppelte Abfrage der Nachricht in cout kommt bis das Ergebnis ausgegeben wird.</p>
<pre><code>#include &lt;iostream&gt;
#include &quot;badgeCalc.h&quot;
using namespace std;

int main()
{

BadgeCalc b;

b.dialog();
b.eingabe(b);
b.calc(b);
b.result(b);

cout &lt;&lt;&quot;jahre: &quot; &lt;&lt; b.getYears() &lt;&lt; &quot;\n&quot;;
cout &lt;&lt; &quot;Ausbildung: &quot; &lt;&lt; b.getAusbildung() &lt;&lt; '\n';

}
</code></pre>
<pre><code>#include &lt;iostream&gt;
#include &quot;badgeCalc.h&quot;

using namespace std;

const int BadgeCalc::getYears()const{
    return years;
    }

const int BadgeCalc::getAusbildung()const{
    return ausbildung;
    }

void BadgeCalc::dialog ()const{

    cout &lt;&lt; &quot;Bitte geben Sie die Dienstjahre ein: \n&quot;;
    cout &lt;&lt; &quot;Bitte wählen Sie die passende Zahl zum höchsten Ausbildungsstand: \n&quot;;
    cout &lt;&lt; &quot;0:Keine Ausbildung \n&quot; &lt;&lt; &quot;1: Grundausbildung \n&quot; &lt;&lt; &quot;2: Sprechfunker,Atemschutz,Maschinist \n&quot;&lt;&lt; &quot;3: Truppfuehrer \n&quot; &lt;&lt; &quot;4: Gruppenfuehrer \n&quot;
         &lt;&lt; &quot;5: Ausbilder \n&quot; &lt;&lt; &quot;6: Zugfuehrer \n&quot;&lt;&lt; &quot;7: Verbandsfuehrer \n&quot;;

}

void BadgeCalc::setYears(int y){

years = y;
}

void BadgeCalc::setAusbildung(int c){

ausbildung = c;

}

const int BadgeCalc::eingabe(BadgeCalc&amp; b){

    int years;
    int c;

    cin &gt;&gt; years;
    cin &gt;&gt; c;
    b.setYears(years);
    b.setAusbildung(c);

}

int BadgeCalc::calc(BadgeCalc&amp; b){
    int gf;
    int y = b.years;
    char c = b.ausbildung;

    if(y == 0){
        return 0;
        }
    else if(y&gt;0  &amp;&amp; (c == 1) &amp;&amp; y &lt; 11){
        return 1;

        }

    else if(y &gt;= 11 &amp;&amp; c &lt; 4|| (y &gt;= 4 &amp;&amp; c == 2)){
        return 2;

        }

    else if(y &gt;= 21 &amp;&amp; c &lt; 4 || (y &gt;= 16 &amp;&amp; c == 3) || (y &gt;= 9 &amp;&amp; c == 3)){
        return 3;

        }
    else if(y &gt;= 1 &amp;&amp; c == 4){
        int gf;
        cout &lt;&lt; &quot;Seit wann ist die die Person GF?: \n&quot;; // Diese Abfrage erscheint dppelt
        cin &gt;&gt; gf;
        if(gf &lt;10 ){
            return 4;
            }
        else if(gf &gt;= 15){
            return 6;
            }
        else{
            return 5;
        }
        }
    else if(y &gt;= 1 &amp;&amp; c == 5){

        cout &lt;&lt; &quot;Seit wann ist die Person GF?: &quot;; // Diese Abfrage erscheint dppelt
        cin &gt;&gt; gf;
        if(gf &lt;5 ){
            return 4;
            }
        else if(gf &gt;= 10){
            return 6;
            }
        else {
            return 5;
            }
        }
    else if(y &gt;= 1 &amp;&amp; c == 6){
        int zf;
        cout &lt;&lt; &quot;Seit wann ist die Person ZF: &quot;; // Diese Abfrage erscheint dppelt
        cin &gt;&gt; zf;
        if(zf &lt; 10){
            return 7; }

        else if(zf &gt;= 20){
            return 9;
            }
        else {
        return 8;
        }
      }
    else if(y &gt;= 1 &amp;&amp; c == 7){
        int zf;
        cout &lt;&lt; &quot;Seit wann ist die Person ZF: &quot;;
        cin &gt;&gt; zf;
        if(zf &lt; 5){
            return 7;
            }
        else if(zf &gt;= 15){
            return 9;
            }
        else{
            return 8;
            }
        }
    else {cout &lt;&lt; &quot;Fehlerhafte Eingabe!&quot;;
        }

}

const void BadgeCalc::result(BadgeCalc&amp; b){
    int res = b.calc(b);
    cout &lt;&lt; &quot;Abzeichen Nummer: &quot; &lt;&lt; res &lt;&lt; '\n';

}
</code></pre>
<pre><code>#ifndef BADGECALC_H_INCLUDED
#define BADGECALC_H_INCLUDED

class BadgeCalc{

public:

    const int getYears()const;
    const int getAusbildung()const;
    void setYears(int years);
    void setAusbildung(int ausbildung);
    void dialog()const;
    int calc(BadgeCalc&amp; b);
    const int eingabe(BadgeCalc&amp; b);
    const void result(BadgeCalc&amp; b);

private:

int years;
int ausbildung;

};

#endif
</code></pre>
<p>Falls mir jemand weiterhelfen kann würde ich mich sehr über eine Rückmeldung freuen <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="🙂"
    /></p>
<p>LG<br />
Marci</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2489274</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2489274</guid><dc:creator><![CDATA[b4shyou]]></dc:creator><pubDate>Thu, 03 Mar 2016 18:01:28 GMT</pubDate></item><item><title><![CDATA[Reply to Doppelte Ausgabe in else if Abfragen wegen Objekt? on Thu, 03 Mar 2016 18:11:40 GMT]]></title><description><![CDATA[<p>Mal abgesehen von der Qualität deines Codes, rufst du zwei mal calc auf:</p>
<pre><code>//in main
b.calc(b);

const void BadgeCalc::result(BadgeCalc&amp; b){
    int res = b.calc(b);
    cout &lt;&lt; &quot;Abzeichen Nummer: &quot; &lt;&lt; res &lt;&lt; '\n';

}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2489275</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2489275</guid><dc:creator><![CDATA[FA43A]]></dc:creator><pubDate>Thu, 03 Mar 2016 18:11:40 GMT</pubDate></item><item><title><![CDATA[Reply to Doppelte Ausgabe in else if Abfragen wegen Objekt? on Thu, 03 Mar 2016 19:43:28 GMT]]></title><description><![CDATA[<blockquote>
<p>Ich bin gerade dabei C++ zu lernen und hab mich heute an der Objektorientierung versucht.</p>
</blockquote>
<p>Das sieht eher nach gemurkse aus. Besorg dir ordentliches Lehrmaterial, sonst wird das nichts.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2489284</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2489284</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Thu, 03 Mar 2016 19:43:28 GMT</pubDate></item><item><title><![CDATA[Reply to Doppelte Ausgabe in else if Abfragen wegen Objekt? on Fri, 04 Mar 2016 11:08:40 GMT]]></title><description><![CDATA[<p>Vielen Dank für eure Antworten!<br />
Jetzt macht er was er soll...</p>
<p>Ich weiß, dass der Code nicht gerade toll ist aber was ist denn jetzt genau das Problem daran.<br />
Ist es das Aussehen oder die Art der OOP?</p>
<p>Über ein paar Informationen dazu würd ich mich sehr freuen</p>
<p>LG</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2489336</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2489336</guid><dc:creator><![CDATA[b4shyou]]></dc:creator><pubDate>Fri, 04 Mar 2016 11:08:40 GMT</pubDate></item><item><title><![CDATA[Reply to Doppelte Ausgabe in else if Abfragen wegen Objekt? on Fri, 04 Mar 2016 11:57:38 GMT]]></title><description><![CDATA[<p>b4shyou schrieb:</p>
<blockquote>
<p>Ich weiß, dass der Code nicht gerade toll ist aber was ist denn jetzt genau das Problem daran.<br />
Ist es das Aussehen oder die Art der OOP?</p>
<p>Über ein paar Informationen dazu würd ich mich sehr freuen</p>
</blockquote>
<p>Wie schon gesagt, besorg dir ordentliches Lehrmaterial. Beispielhaft zwei Kritikpunkte:</p>
<p>OOP ist <strong>nicht</strong>, ein C Programm nehmen und einmal class drumstricken. Warum sind all die Funktionen Member der <strong>einen</strong> Klasse?</p>
<pre><code class="language-cpp">b.eingabe(b);
</code></pre>
<p>Wozu wird b übergeben? eingabe kennt sein b schon.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2489337</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2489337</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Fri, 04 Mar 2016 11:57:38 GMT</pubDate></item></channel></rss>