Is a number prime

Hello I got a task, and I don't have any idea how to do it. Maybe you can help me?

There is given a whole number (that you need to insert by yourself using the command cin>>), and I need to determine is that number a prime or not. If it's a prime number I need to cout >> "1" and if it's not cout "0" , also it's mandatory to use the function:
bool IsPrime(long long a)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>
#include <iomanip>

using namespace std;


int main()
{
char answer = 'y';
int prime;
bool isPrime(int prime);
while (answer == 'y' || answer == 'Y')
{
cout << "Please enter an integer and I will tell you if it is prime: " << endl;
cin >> prime;
if (prime <= 0)
{
cout << "Please make sure the number is above 0." << endl;
cin >> prime;
if (prime <=0)
{
cout << "The program will now terminate." << endl;
system("pause");
return 0;
}
}


if (isPrime(prime))

cout << prime << " is a prime number. " << endl;

else
cout << prime << " is not a prime number. " << endl;
system ("pause");
system("cls");
cout << "Would you like to try again? , enter (Y/y or N/n)" << endl;
cin >> answer;



}

return 0;
}


bool isPrime(int a)
{

for ( int i = 2; i <= a/2; i++)
{
if (a % i ==0)
return 0;
}

return true;

}

this is your code..
Topic archived. No new replies allowed.