Prime Numbers Disconnect

How do I get this to work?

[i]The problem:[i] use bool isPrime(int) for a looping program that gets a number between 1-29 from user, output will say if it is prime or not, and they continue.

[i]The solution should look like:[i]
Enter a number
3
3 is a prime number.
Enter another number
8
8 is not a prime number.
and so on.

There doesn't seem to be an escape, it looks like they should go through the entire range.

For grading we are to use global constants and modules. When I put the constants in they don't seem to work.

What I've got will only go as far as displaying the number.
Thank you for your help.



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
71
72
73
74
75
76
77
78
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <stdbool.h> 

using namespace std;

//function prototypes
bool isPrime(int numero);

//global constants

const int PRIME_A = 0;
const int PRIME_B = 2;


int main()
{
	int	uNum = 0;
	int i = 0;
//	int //needs random number generator?
	
	cout<<"Test for Prime Numbers."<<endl;
	
	
	cout<<"Enter a positive number."<<endl;
	cin>>uNum;
	
		
	for (i=2; i <= 2; i++)
	{
	  while (i >= 2 && i <= 29)
	  {
	  	cin>>uNum;
	   
	    break;
	  }
	}
	isPrime(uNum);
	
	cout<<"Enter another number."<<uNum <<endl;
	    
	
	cin.get();
	cin.get();
	
	return 0;
	
}

bool isPrime(int numero)
{
	int i;
	int numPnP;
//	const int PRIME_A = 0;
//	const int PRIME_B = 2;

	
  	if (i <= PRIME_B && i % PRIME_B == PRIME_A )
	{
	  cin>>numPnP;	
	  cout<<"This is not a prime number."<<numPnP<<endl;
	  return false;
	  
	}
	else 
	{
      cin>>numPnP;
	  cout<<"This is a prime number."<<numPnP<<endl;

      return true;

	}
	
}
    

  
Although the question you were given is not quite clear to me, I think the structure of the program should be something like this:
Note there is no use of cin or cout inside the function isPrime()

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
#include <iostream>
#include <cstdlib>
#include <cmath>

using namespace std;

//function prototypes
bool isPrime(int numero);

int main()
{
    int    uNum = 0;

    cout << "Test for Prime Numbers." << endl;
    cout << "\nEnter a number: ";
    cin >> uNum;

    while (uNum > 0 && uNum < 30)
    {
        // Test whether or not the number is prime

        // Here, call the function isPrime(uNum))
        // and output the appropriate message 
        // depending upon the returned value.
        cout << "This is / is not a prime number." << endl;

        cout << "\nEnter a number: ";
        cin >> uNum;
    }

    cout << "Done." << endl;

    cin.get();
    cin.get();

    return 0;
}

bool isPrime(int numero)
{
    // add appropriate code here to test whether or not
    // the number is prime, and return true or false as appropriate
    return true;
}
Thank you. This helped in getting it working.
Topic archived. No new replies allowed.