Nth prime number calculation

I only just recently started learning C++ a few months ago. So i'm not sure how to go about this. In the function int prime(num)the num value should be returned to int(main), I've tried multiple times to fix it, but simply could not figure it out. #include "stdafx.h"
#include <iostream>
using namespace std;

bool IsPrime(int num)
{
if (num != 2) {
if (num < 2 || num % 2 == 0) {
return false;
}
for (int i = 3; (i*i) <= num; i += 2) {
if (num % i == 0) {
return false;
}
}
}
return true;
}

int Prime(int n)
{
int checkprime;
int nthplace=0;
int num=0;
n;

IsPrime(num);
if (true)
for (int num = 2; num <= 10001; num++)
{
checkprime = 0;

for (int i = 2; i <= num / 2; i++)
{

if (num%i == 0)
{
checkprime = 1;
break;
}

}

if (checkprime == 0)
nthplace++;

if (nthplace == n)
cout << n << " Prime num is: " << num << endl;

}
return num++;
}

int main()
{
char yon;
int n;
int num=0;
do {

cout << "Which nth Placed Prime num Are You Looking For? ";
cin >> n;

Prime(n);
num; // num isn't being returned
cout << n << " Prime num is: " << num << endl;

cout << "Would You Like To Find Another Prime num? (Y/N) ";
cin >> yon;
yon = yon | 0x20;

while (yon != 'y' && yon != 'n') {
cout << "Invalid Response, please enter \"Y\" or \"N\": ";
cin >> yon;
yon = yon | 0x20;
}
} while (yon == 'y');

cout << "\nThank you for using this awesome program\n" << endl;
return 0;
}

I realize there is a redundancy in the functions, but I'm more focused on the problem of the value not returning.
Last edited on
 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485`` ``````#include "stdafx.h" #include using namespace std; bool IsPrime(int num) { if (num != 2) { if (num < 2 || num % 2 == 0) { return false; } for (int i = 3; ( i*i ) <= num; i += 2) { if (num % i == 0) { return false; } } } return true; } int Prime(int n) { int checkprime; int nthplace = 0; int num = 0; n; IsPrime(num); if (true) for (int num = 2; num <= 10001; num++) { checkprime = 0; for (int i = 2; i <= num / 2; i++) { if (num%i == 0) { checkprime = 1; break; } } if (checkprime == 0) nthplace++; if (nthplace == n) cout << n << " Prime num is: " << num << endl; } return num++; } int main() { char yon; int n; int num = 0; do { cout << "Which nth Placed Prime num Are You Looking For? "; cin >> n; Prime(n); num; // num isn't being returned cout << n << " Prime num is: " << num << endl; cout << "Would You Like To Find Another Prime num? (Y/N) "; cin >> yon; yon = yon | 0x20; while (yon != 'y' && yon != 'n') { cout << "Invalid Response, please enter \"Y\" or \"N\": "; cin >> yon; yon = yon | 0x20; } } while (yon == 'y'); cout << "\nThank you for using this awesome program\n" << endl; return 0; }``````
Secondly, not addressing other issues, you aren't assigning the value to `num`. You're just discarding it.
`num = Prime(n);` will actually make the assignment.