Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ finding all prime numbers from 1 to a number entered
    text
    copied!<p>So the point is to have the program find and list all prime numbers between 1 and the number you enter. I'm using number_test as the number tested for prime, and divisor and the number to divide by.</p> <p>I'm not sure what's wrong, as to me it looks functionally the same as the program posted here: <a href="https://stackoverflow.com/questions/5200879/printing-prime-numbers-from-1-through-100">Printing prime numbers from 1 through 100</a> with some minor changes (inputting a number, changing "i" to less than the number entered).</p> <p>I've been looking for the past three or four days, and I haven't found anything that really answers this question fully, to the degree I need for class. Any help is much appreciated.</p> <pre><code>#include iostream #include conio.h using namespace std; void main(void){ //Declare variables int number_entered; //Get inputs cout &lt;&lt; "This program lists all prime numbers from 1 through a positive number entered." &lt;&lt; endl; cout &lt;&lt; "Please enter a positive integer." &lt;&lt; endl; cin &gt;&gt; number_entered; cout &lt;&lt; "Displaying all numbers from 1 to " &lt;&lt; number_entered &lt;&lt; endl &lt;&lt; "Press any key to continue..." &lt;&lt; endl; getch(); for(int number_test = 2; number_test &lt; number_entered; number_test++){ for(int divisor = 2; divisor &lt; number_test; divisor++){ if(number_test % divisor == 0){ break; } else if(number_test % divisor != 0){ cout &lt;&lt; number_test &lt;&lt; " "; break; } } } getch(); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload