<?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[cin-Probleme in for-Schleife]]></title><description><![CDATA[<p>Hallo ihr Lieben,<br />
kann mir bitte jemand sagen warum in diesem Programm der CIN Aufruf nicht funktioniert. Und zwar das cin in der ersten for-Schleife in diesem Code.<br />
Die Schleife wird sicher durchlaufen, das kann man erkennen weil ich zum test +-Zeichen ausgebe. Aber das CIN fragt den Benutzer nicht ab was er eingeben will. Falls mir jemand weiterhelfen kann, herzlichen DANK!</p>
<pre><code class="language-cpp">#include &lt;cstdlib&gt;
#include &lt;iostream&gt;
using namespace std;

double innenprodukt (double A[], double B[], int);

int main()
{   
    const int size=100;
    double A[size]={}, B[size]={};

    cout&lt;&lt;&quot;Skalarprodukt berechnen\n\nBitte 1. Vektor eingeben: &quot;&lt;&lt;endl;

    int i=0;
    while ( cin&gt;&gt;A[i] )
    {
        i++;
    }

    cout&lt;&lt;&quot;Bitte 2. Vektor mit der Dimension &quot; &lt;&lt;i &lt;&lt;&quot;eingeben: &quot;&lt;&lt;endl;

    double temp=0;
    fflush(stdin);
    fflush(stdout);

    for(int j=0; j&lt;i; j++) 
    {

        cin&gt;&gt;B[j];
        cout&lt;&lt;&quot; + &quot;;
    }
    /*{
        scanf(&quot;%f&quot;, &amp;B[j]);     // cin&lt;&lt;B[j] funktionierte in for Schleife nicht
        //B[j]=temp;
    }*/

    cout&lt;&lt;&quot;Das Skalarprodukt wird berechnet: &quot; //&lt;&lt; B[0] &lt;&lt; B[1] &lt;&lt; B[2] 
        &lt;&lt; &quot; = &quot; &lt;&lt; innenprodukt(A, B, i)
        &lt;&lt; endl;

    system(&quot;PAUSE&quot;);
    return 0;
}

double innenprodukt (double A[], double B[], int k)
{
    double value1=0, value2=0, erg=0;

    for (int j=0; j&lt;k; j++)
    {
        value1=A[j]*B[j];
        value2+=value1;
    }
    erg = value2/k;
    return erg;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/281234/cin-probleme-in-for-schleife</link><generator>RSS for Node</generator><lastBuildDate>Sun, 23 Aug 2026 19:24:15 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/281234.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 29 Jan 2011 08:30:26 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to cin-Probleme in for-Schleife on Sat, 29 Jan 2011 08:30:26 GMT]]></title><description><![CDATA[<p>Hallo ihr Lieben,<br />
kann mir bitte jemand sagen warum in diesem Programm der CIN Aufruf nicht funktioniert. Und zwar das cin in der ersten for-Schleife in diesem Code.<br />
Die Schleife wird sicher durchlaufen, das kann man erkennen weil ich zum test +-Zeichen ausgebe. Aber das CIN fragt den Benutzer nicht ab was er eingeben will. Falls mir jemand weiterhelfen kann, herzlichen DANK!</p>
<pre><code class="language-cpp">#include &lt;cstdlib&gt;
#include &lt;iostream&gt;
using namespace std;

double innenprodukt (double A[], double B[], int);

int main()
{   
    const int size=100;
    double A[size]={}, B[size]={};

    cout&lt;&lt;&quot;Skalarprodukt berechnen\n\nBitte 1. Vektor eingeben: &quot;&lt;&lt;endl;

    int i=0;
    while ( cin&gt;&gt;A[i] )
    {
        i++;
    }

    cout&lt;&lt;&quot;Bitte 2. Vektor mit der Dimension &quot; &lt;&lt;i &lt;&lt;&quot;eingeben: &quot;&lt;&lt;endl;

    double temp=0;
    fflush(stdin);
    fflush(stdout);

    for(int j=0; j&lt;i; j++) 
    {

        cin&gt;&gt;B[j];
        cout&lt;&lt;&quot; + &quot;;
    }
    /*{
        scanf(&quot;%f&quot;, &amp;B[j]);     // cin&lt;&lt;B[j] funktionierte in for Schleife nicht
        //B[j]=temp;
    }*/

    cout&lt;&lt;&quot;Das Skalarprodukt wird berechnet: &quot; //&lt;&lt; B[0] &lt;&lt; B[1] &lt;&lt; B[2] 
        &lt;&lt; &quot; = &quot; &lt;&lt; innenprodukt(A, B, i)
        &lt;&lt; endl;

    system(&quot;PAUSE&quot;);
    return 0;
}

double innenprodukt (double A[], double B[], int k)
{
    double value1=0, value2=0, erg=0;

    for (int j=0; j&lt;k; j++)
    {
        value1=A[j]*B[j];
        value2+=value1;
    }
    erg = value2/k;
    return erg;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2013789</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2013789</guid><dc:creator><![CDATA[Radioactive_Man]]></dc:creator><pubDate>Sat, 29 Jan 2011 08:30:26 GMT</pubDate></item><item><title><![CDATA[Reply to cin-Probleme in for-Schleife on Sat, 29 Jan 2011 09:09:19 GMT]]></title><description><![CDATA[<p>Warum in Zeile 6 und 11 &quot;double A[] + double B[]&quot;?</p>
<p>Hab das nicht getestet, aber macht den Quelltext nicht leicht zu lesen.</p>
<p>Geb das in einer der Zeilen mal einen anderen Namen.</p>
<p>MfG</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2013790</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2013790</guid><dc:creator><![CDATA[f.-th.]]></dc:creator><pubDate>Sat, 29 Jan 2011 09:09:19 GMT</pubDate></item><item><title><![CDATA[Reply to cin-Probleme in for-Schleife on Sat, 29 Jan 2011 09:15:48 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;cstdlib&gt;
#include &lt;iostream&gt;
using namespace std;

double innenprodukt (double Vektor1[], double Vektor2[], int);  // Prototyp

int main()
{   
    const int size=100;
    double A[size]={}, B[size]={};

    cout&lt;&lt;&quot;Skalarprodukt berechnen\n\nBitte 1. Vektor eingeben: &quot;&lt;&lt;endl;

    int i=0;
    while ( cin&gt;&gt;A[i] )
    {
        i++;
    }

    cout&lt;&lt;&quot;Bitte 2. Vektor mit der Dimension &quot; &lt;&lt;i &lt;&lt;&quot;eingeben: &quot;&lt;&lt;endl;

    double temp=0;
    fflush(stdin);
    fflush(stdout);

    for(int j=0; j&lt;i; j++) 
    {

        cin&gt;&gt;B[j];
        cout&lt;&lt;&quot; + &quot;;
    }
    /*{
        scanf(&quot;%f&quot;, &amp;B[j]);     // cin&lt;&lt;B[j] funktionierte in for Schleife nicht
        //B[j]=temp;
    }*/

    cout&lt;&lt;&quot;Das Skalarprodukt wird berechnet: &quot; //&lt;&lt; B[0] &lt;&lt; B[1] &lt;&lt; B[2] 
        &lt;&lt; &quot; = &quot; &lt;&lt; innenprodukt(A, B, i)
        &lt;&lt; endl;

    system(&quot;PAUSE&quot;);
    return 0;
}

double innenprodukt (double Vektor1[], double Vektor2[], int k)   // Funktion
{
    double value1=0, value2=0, erg=0;

    for (int j=0; j&lt;k; j++)
    {
        value1 = Vektor1[j]*Vektor2[j];
        value2 += value1;
    }
    erg = value2/k;
    return erg;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2013791</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2013791</guid><dc:creator><![CDATA[Radioactive_Man]]></dc:creator><pubDate>Sat, 29 Jan 2011 09:15:48 GMT</pubDate></item><item><title><![CDATA[Reply to cin-Probleme in for-Schleife on Sat, 29 Jan 2011 11:50:49 GMT]]></title><description><![CDATA[<p>Schau dir Zeile 16 an - das ist mindestens ungewöhnlich.</p>
<p>Und Zeile 25 ist nur auf Microsoft Compilern eine Idee - bei anderen Compilrern kann das zu undefinierbarem Verhalten deines Programms führen!</p>
<p>MfG f.-th.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2013816</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2013816</guid><dc:creator><![CDATA[f.-th.]]></dc:creator><pubDate>Sat, 29 Jan 2011 11:50:49 GMT</pubDate></item><item><title><![CDATA[Reply to cin-Probleme in for-Schleife on Sat, 29 Jan 2011 12:31:07 GMT]]></title><description><![CDATA[<p>Die Idee von Zeile 16 lautet;<br />
Gehe so oft in die Schleife, solange eine Zahl eingegeben wird. Sobald der Benutzer einen Buchstaben eingibt, ist die Bedingung falsch, also ist man mit der Eingabe fertig.<br />
Auf diese Art das Array einzulesen, war nicht von mir. Sie hat ein Dozent schon einmal angewendet. Ich glaube das das nicht das Problem ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2013824</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2013824</guid><dc:creator><![CDATA[Radioactive_Man]]></dc:creator><pubDate>Sat, 29 Jan 2011 12:31:07 GMT</pubDate></item><item><title><![CDATA[Reply to cin-Probleme in for-Schleife on Sat, 29 Jan 2011 12:58:56 GMT]]></title><description><![CDATA[<p>jetzt läuft es...</p>
<pre><code class="language-cpp">#include &lt;cstdlib&gt;
#include &lt;iostream&gt;
#include &lt;iomanip&gt;
#include &lt;stdio.h&gt;
using namespace std;

double innenprodukt (double Vektor1[], double Vektor2[], int);

int main()
{   
    const int size=100;
    double A[size]={}, B[size]={};
    cout&lt;&lt;&quot;Skalarprodukt berechnen\n\nBitte 1. Vektor eingeben: &quot;&lt;&lt;endl;

    int i=0;
    while ( cin&gt;&gt;A[i] )
    {
        i++;
    }

    cout&lt;&lt;&quot;Bitte 2. Vektor mit der Dimension &quot; &lt;&lt;i &lt;&lt;&quot; eingeben: &quot;&lt;&lt;endl;

    double temp=0;

    fflush(stdin);                // &lt;--- !!!
    cin.clear();                  // &lt;--- !!!

    for(int j=0; j&lt;i; j++) 
    {

        cin&gt;&gt;B[j];
        //cout&lt;&lt;&quot; + &quot;;
    }

    cout&lt;&lt;&quot;Das Skalarprodukt wird berechnet: &quot; //&lt;&lt; B[0] &lt;&lt; B[1] &lt;&lt; B[2] 
        &lt;&lt; &quot; = &quot; &lt;&lt; innenprodukt(A, B, i)
        &lt;&lt; endl;

    system(&quot;PAUSE&quot;);
    return 0;
}

double innenprodukt (double Vektor1[], double Vektor2[], int k)
{
    double value1=0, value2=0, erg=0;

    for (int j=0; j&lt;k; j++)
    {
        value1 = Vektor1[j]*Vektor2[j];
        value2 += value1;
    }
    erg = value2/k;
    return erg;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2013828</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2013828</guid><dc:creator><![CDATA[Radioactive_Man]]></dc:creator><pubDate>Sat, 29 Jan 2011 12:58:56 GMT</pubDate></item><item><title><![CDATA[Reply to cin-Probleme in for-Schleife on Sat, 29 Jan 2011 13:27:05 GMT]]></title><description><![CDATA[<p>Schade, wenn nicht mal der Prof C++ kann.</p>
<p>Überleg dir mal was passiert, wenn mehr als 100 Eingaben erfolgen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61b.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_tongue"
      title=":P"
      alt="😛"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2013842</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2013842</guid><dc:creator><![CDATA[moep]]></dc:creator><pubDate>Sat, 29 Jan 2011 13:27:05 GMT</pubDate></item><item><title><![CDATA[Reply to cin-Probleme in for-Schleife on Sat, 29 Jan 2011 13:29:01 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">while ( cin&gt;&gt;A[i] &amp;&amp; i&lt;100 )
</code></pre>
<p><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/2013844</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2013844</guid><dc:creator><![CDATA[Radioactive_Man]]></dc:creator><pubDate>Sat, 29 Jan 2011 13:29:01 GMT</pubDate></item><item><title><![CDATA[Reply to cin-Probleme in for-Schleife on Sat, 29 Jan 2011 18:38:19 GMT]]></title><description><![CDATA[<p>Okay hab es mal durch ein paar Compiler geschickt.<br />
Der eine gcc kann das. Aber unter welcher IDE hast du das getestet?<br />
Die stellen das Ergebnis unterschiedlich dar <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f62e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_open_mouth"
      title=":open_mouth:"
      alt="😮"
    /><br />
Und wie viele Werte hast du zum testen eingegeben - oder gibst du da jedes mal 100 werte ein? Zum Test setze den Wert mal auf etwas überschaubares und, wenn soweit alles läuft kannst du ja auch mit 100 Werten testen.</p>
<p>Der zweite Compiler weigert sich. Behauptet Fehler in Zeile 11, 32 und 43.</p>
<p>MfG f.-th.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2013981</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2013981</guid><dc:creator><![CDATA[f.-th.]]></dc:creator><pubDate>Sat, 29 Jan 2011 18:38:19 GMT</pubDate></item><item><title><![CDATA[Reply to cin-Probleme in for-Schleife on Sun, 30 Jan 2011 18:10:13 GMT]]></title><description><![CDATA[<p>Hi,<br />
du brauchst nicht 100 Werte eingeben. Gib einfach für den ersten Vektror so viele Zahlen wie du lust hast, und beende die schleife mit einem buchstaben.</p>
<p>Ich benutze wx Dev-C++</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2014304</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2014304</guid><dc:creator><![CDATA[Radioactive_Man]]></dc:creator><pubDate>Sun, 30 Jan 2011 18:10:13 GMT</pubDate></item></channel></rss>