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
#include<iomanip>
#include<iostream>
#include<string>
usingnamespace 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.