First, there are syntax errors.
Second, always use curly braces with if/else
unless you know what you are doing - there's an error related to this.
Third, using system()
requires #include <cstdlib>
. Your compiler is lax if it allows you to not to (g++
doesn't).
Fourth, pause
is not a standalone program but a cmd.exe
builtin so system()
may fail depending on the compiler/environment used. A neater way is C++ keypress: getch, cin.get? .
Finally, your algorithm is highly suboptimal. E.g. y
only needs to go up to x/2+1
and it's reasonable to store the primes already found in an array/list and try only them.