I'm trying to write this program to test and output all prime numbers in a range given by the user. I posted this code before, but I have a different problem now. Right now, it mostly works except that when the outputs are in the single digits, then it won't output as I want, but anything past that, it will output everything correctly as far I can tell. I also had the inside if written as if (start % div == 0 || start % 3 == 0), which also let single digits primes (except 2) print out, but then higher number non-primes, starting at 49 I think, started to output. I was also thinking about using a bool flag which I added in a variable for, but don't quite know how to use.
> but anything past that, it will output everything correctly as far I can tell
no, if the condition in line 24 fails then the one ine line 26 would succeed, always.
what's more, either path woud terminate the loop.
`div' would no go farther than 4, you only test against 2, 3, 4, 5, and 7.
Review the conditions for a number to be prime.
Also, to simplify the code, create a function bool is_prime(int number) then you may do
1 2 3
for(int number = start; number <= finish; ++number)
if( is_prime(number) )
std::cout << number << ' ';