#include <iostream>
#include <cmath>
usingnamespace std;
int main() {
int n;
int i;
int is_prime = true;
cout << "Enter a number and press Enter: ";
cin >> n;
i = 2;
while (i <= sqrt(n)) {
if (n % i == 0)
is_prime = false;
i++;
}
if (is_prime)
cout << "Number is prime." << endl;
else
cout << "Number is not prime." << endl;
system("pause");
return 0;
}
People generally aren't just gonna FIX your code for you...especially if they have no idea what you are asking?
1st - I ran the code just out of curiosity and I see nothing wrong with it...seems to report things correctly.
2nd - I think a proper way to call is_prime would be with "bool" - may want to look up for more clarification (bool = true/false answers vs int which wants to assign numbers).