This code is supposed to find the nth prime number (n being input by the user). I have the code to calculate whether a number is prime or not, but I don't know how to get the code to display the nth prime number.
#include <iostream>
using namespace std;
void isprime(int);
int main ()
{
int x;
cout << "Which prime number would you like to display? ";
cin >> x;
if (x==0)
{
cout << "That is not a valid choice. Please enter another number." << endl;
cin >> x;
}
if (x<0)
{
cout << "That is not a valid choice. There are no negative prime numbers. Please enter another number." << endl;
cin >> x;
}
return 0;
}
void isprime(int x)
{
cout << "Enter a number: ";
int n;
cin >> n;
int isprime;
if(n<2 || n>2 && n%2==0)
{
isprime=0;
for(int i=2; i<n; i++)
{
if((n%i)==0)
{
isprime=0;
}
}
}
else isprime=1;
}