title: C++ question on prime numbers
body: <p>I am trying to make a program that determines if the number is prime or composite. I have gotten thus far. Could you give me any ideas so that it will work? All primes will , however, because composites have values that are both r>0 and r==0, they will always be classified as prime. How can I fix this?</p>
  
  <pre><code>int main()
  {
      int pNumber, limit, x, r;               
      limit = 2;
      x = 2;
  
      cout &lt;&lt; "Please enter any positive integer: " ;
      cin &gt;&gt; pNumber;
  
      if (pNumber &lt; 0)
      {
          cout &lt;&lt; "Invalid. Negative Number. " &lt;&lt; endl;
          return 0;
      }
      else if (pNumber == 0)
      {   
          cout &lt;&lt; "Invalid. Zero has an infinite number of divisors, and therefore neither composite nor prime." &lt;&lt; endl;
          return 0;
      }
      else if (pNumber == 1)
      {
          cout &lt;&lt; "Valid. However, one is neither prime nor composite" &lt;&lt; endl;
          return 0;
      }
      else
      {
          while (limit &lt; pNumber)
          {
              r = pNumber % x;
              x++;
              limit++;
  
              if (r &gt; 0)
                  cout &lt;&lt; "Your number is prime" &lt;&lt; endl;
              else 
              {
                  cout &lt;&lt; "Your number is composite" &lt;&lt; endl;
                  return 0;
              }
          }
      }
  
      return 0;
  }
  </code></pre>