You don't have a problem with atoi
specifically, though you aren't checking to see if it worked correctly.
The real problem is that your program divides by zero on the first iteration of the loop. Start x
at 2
:
for (int x = 2; x < maxX; x++)
You do have to start at 2
, too. Starting at 1
will tell you that all of your numbers are prime, which isn't true and probably isn't what you want. You might need a special case to handle 0
and 1
inputs - they're not prime, but will fall out of your current algorithm.
Editorial aside: There are plenty of faster ways to check if a number is prime, if that's of use to you.