I'm trying to output prime numbers in an user inputted range, but with testing, when I input 1 and 10, it'll show all the prime numbers, but it will also input 1. I've tried rearranging and deleting/adding code, but it only seems to make it worse. This is my for/if loop that works with the '1' being outputted.
Well, a prime number by definition is a number that is divisible by 2 divisors, that number and 1. I realize that, but in the book I have, it shows in a range of 1-10, the numbers should output 2, 3, 5, and 7.
First of all, thank you @LB for pointing that out, I had forgotten.
Your problem is in the second for-loop.
Since it's int div = 2; div < testNum; And testNum starts at 1, it will skip that for-loop and directly go to the if (prime) and print out the number 1.
If you don't want it to print out the number 1, you need to start your bool as false, rather than true. So just change
bool prime = true; to bool prime = false; and it should run perfectly fine.
Edit: I found out the problem in 30 seconds by debugging the program. Debugging is very important and you should definitely learn how to do it.
Honestly I would just take LB's advice. I don't see any reason as to why you would want to start at 1, other than your book saying it, which you don't have to listen to really. Just use your original code and do the logical thing of starting at 2, saves you a lot of time and headache.