Prime number function

I am writing a code for asking a user for a number between 3 and 100, and determining if its prime. I have 90% of the code written, and it works but I am struggling with an equation for determining if a number is prime. Below is what i currently have:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
int isprime (int num) {
int answer;
answe = (num/num);
return answer;
}
int main () {
int num;
cin>> num;
int answer;
cout<< Please enter a number between 3 and 100";
answer = isprime(num);
cout<< num;
cout<< endl;
if (answer ==1) {
cout<< "is prime";
cout<< endl;
}
else {
cout<< "is not prime";
cout<< endl;
}
return 0;
} 
Line 3 you wrote answe instead of answer.

Line 10 missing a " before Please.

You should have the cin after the cout and before answer = isprime(num);

Your function isprime() will always return 1. A number divided by itself is always equal to 1.

Remeber a prime number is a number whose only divisors are 1 and itself.
i tried a "if statement" but that doesnt seem logical once i typed it in, and did not yield a result i tried:

if ((answer =1) && answer %2))

but I am not sure how to finish it from this point
What i meant is that isprime(num) should loop through all numbers between 2 and num-1 and if num mod n == 0 return false else return true.
Topic archived. No new replies allowed.