I need to write two separate functions (preferrably void), one that determines whether it is a prime number, the second one that inputs an upper bound and displays all prime numbers from 3 up to the upper bound using the previous (one) function (called inside a loop) to do this. This is what I have so far and while it compiles all it does is receive the input value. Any tips? Thanks!
1st function isPrime:
int isPrime( int );
int isPrime(int num)
{
if ( num < 2 )
return 0;
if ( num > 2 && (num % 2) == 0 )
return 0;
for( int i = 2; i <= num; i++ )
if ( (num % i) == 0)
return 0;
return 1;
}
2nd Function findPrime:
void findPrime( int );
int isPrime ( int );
void findPrime( int num )
{
for ( int i = 3; i <= num; )
if ( isPrime( 1 ) )
cout << i << endl;
else
break;
}
Driver:
void findPrime( int );
int main()
{
int num;
do
{
cout << "Enter an integer greater than 2 and I will generate all prime "
<< "numbers up to that integer: ";
cin >> num;
}while (num < 3);