Find The Nth Prime Number

Hi - I am brand new to C++ and am just learning about functions and passing arguments between functions.

Below is my program. In the function int Prime (int n) I am trying to somehow take the code from bool is prime(int num) to determine the nth location of a prime number. Any help is greatly appreciated!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <iostream>
using namespace std;

bool IsPrime(int); //function declaration before it is called, specifies type
int Prime(int); //function declaration before it is called
void main()
{
	char response;
	int n, num, count=0;


	do {
		cout << "Enter F to find the Nth prime number: " << endl;
		cout << "Enter T to test the value to see if it is prime: " << endl;
		cout << "Enter Q to terminate the program: " << endl;
		cin >> response;
		if (response == 't'|| response == 'T'){
			cout << "Enter A Value Greater Than Zero: ";
			cin >> num;
			if (num > 0) {
				if (IsPrime(num) == false) {
					cout << "Your Number Is Not Prime";
				}
				else {
					if (IsPrime(num) == true) {
						cout << "Your Number Is Prime";
					}
				}
			}
			else
				cout << "Enter A Value Greater Than Zero: ";
			cin >> num;
			
		}
		else {
			if (response == 'F' || response =='f') {
				cout << "Enter a Value Greater Than Zero: ";
				cin >> n;
				if (n > 0) {
					cout << "The nth Prime Number where n is " << n << " is " << Prime(n)<< endl;
				}
				else cout << "Your Number Is Invalid."; //get rid of prompt here?
			}
		}

	} 
	while (response != 'Q'); //used code while (response !='Q' || response !='q') 
	//and will not work for either Q or q when or is entered


}
	// for 'T' Value
bool IsPrime(int num) // function declarator 
{

	for (int j = 2; j <= num / 2; j++)
		if (num % j == 0)
			return false; //not prime
	
	return true; //is prime
}
	// for 'F' Value
	int Prime(int n) // function declarator
	{
		int count = 0;
		while (IsPrime(n) == false){
			return count++; 
		}
	}
I am brand new to C++ and am just learning about functions and passing arguments between functions.

Your problem doesn't have anything to do with passing arguments. Prime will always return 0. Trace the logic to discover why.
Topic archived. No new replies allowed.