C++, determine prime number
<p>I've started to read a book on C++ yesterday. So far I'm 100 pages and took that number to write my first programm. I've wanted it to find out if a given number is a prime number or not.</p>

<p>I've got 2 questions about it.</p>

<ol>
<li><p>I know my method is everything else than good. The programm is checking every single number which makes the programm big. What would be the ideal way to do this? Doesn't matter if I understand your answer yet, I'll simply read up the commands later :).</p></li>
<li><p>I've had a huge problem with the <code>"Result+=1"</code> line. At first I had <code>i=1</code>, which gave me the following result for the number <code>7</code>.</p>

<p>1111112</p></li>
</ol>

<p>Well, I also know why. For the 6 first for loops he found one number <code>(1)</code> and for the last one <code>2(1,7)</code>. But thats obviously not how I wanted it work. I want Result to be some kind of counter. How do I do that?</p>

<p>The code:</p>

<pre><code>#include &lt;iostream&gt;
using namespace std;



// Hauptprogramm

int main ()
{

// Variablen
int Prime_number;
int Result = 0;

// Abfragen
cout &lt;&lt; "Please enter possible prime number: ";
cin &gt;&gt; Prime_number;

// Rechnen

for (int i=2; i &lt;= Prime_number ; i++)
{   
    if (Prime_number%i == 0)
    {   
        Result +=1;
    }   
}

// Ausgabe

if(Result == 1)
{
    cout &lt;&lt; "You got a prime number!" &lt;&lt; endl;
}
else
{
    cout &lt;&lt; "No luck" &lt;&lt;endl;
}

return 0;
}
</code></pre>
