Prime Number Program

I am trying to complete a prime number program, and i have the tests to do so, but i can't figure out the syntax or just like loop structure i guess to make them work. Can anyone help? I have a test for modulus 2, at which point it should break out of the loop and tell me it's not a prime, and then i have a second test that tests after it has gone through the loop testing modulus 2 whether or not the "divisor" is equal to n (the number entered) and if it is then the number is prime, and if it isn't the number is not prime. Any help is appreciated. thank! <3Andrea

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include<iomanip>
#include<iostream>
#include<string>
using namespace std;
 int main()
{
	int n = 0;

	cout << "Please enter a number to find out if it is a prime number or not: ";
	cin >> n;

	for(int divisor = 2; divisor < n; divisor++)
	{
		if((n%divisor)== 0)
			break;
		if(divisor == n)
			cout << "This number is prime.";
		else 
			cout << "This number is not prime." <<endl;
		
	}
	
	
	

	system("pause");

return 0;

}
I think the problem lies with the logic. Think about what the three conditional statements are “saying” in the loop. If your still stuck after that let me know.
It looks to me like more or less the right lines of code, but not necessarily in the correct order.
Topic archived. No new replies allowed.