This program was supposed to take input of 6 and return the 6th prime and so on.
#include<iostream>
#include<cmath>
using namespace std;
bool isPrime(int num)
{
int factor=2;
while(factor<=num/2)
{
if(num%factor==0)
return false;
factor++;
}
return true;
}
int main()
{
int num=2, count=0, whichprime;
cin>>whichprime;
while(count<whichprime)
{
if(isPrime(num)==true)
{
count++;
num++;
}
}
cout<<num-1;
}
But, it doesn't work (except for the first and second prime). For the rest, the cursor just keeps blinking at the output page. Can somebody point out the mistake?