I want to write a program that taking some input numbers and then check whether they are prime or not. I wrote it this way:
#include <iostream>
using namespace std;
bool isPrime (int number)
{
for (int i=2; i<number; i++)
{
if(number % i == 0)
return false;
else
return true;
}
}
int main()
{
int y;
bool z;
cout << "Enter a positive integer: ";
cin >> y;
z = isPrime (y);
if(z==true)
cout <<"number is prime" << endl;
else
cout << "number is not prime" << endl;
system("PAUSE");
return 0;
}
As, you can see, I wanted to use a function and for loop. But this code is getting just one number. I want to loop the whole input process. How can I make it ?