why isn't my loop working properly?
im trying to make a simple program that generates 10 random prime numbers and displays them onto the screen. heres the code...
Code:
#include <iostream>
#include <cstdlib>
#include <time.h>
using namespace std;
bool isprime(int num);
int main()
{
int randP = 0,i = 22;
srand( (unsigned)time( NULL ) );
for (int x = 0; x<10; x++)
{
randP = rand() % i; // generate a random number between 0 and the variable 'i'
if (isprime(randP) == true) // if the random number is a prime then display it
cout << randP << endl;
}
cout << endl;
system("Pause");
return 0;
}
bool isprime(int num)
{
bool ya = false;
if (num % 2 == 0)
ya = true;
else
ya = false;
return ya;
}
im not asking 'how do i generate 10 random prime numbers', i just simply want to know why my loop doesn't repeat 10 times like i want it to! to get an idea of what im talking about you have to try the code out for yourself. please help.