### 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.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778`` ``````#include #include #include #include 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."<>uNum; for (i=2; i <= 2; i++) { while (i >= 2 && i <= 29) { cin>>uNum; break; } } isPrime(uNum); cout<<"Enter another number."<>numPnP; cout<<"This is not a prime number."<>numPnP; cout<<"This is a prime number."<
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()`

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344`` ``````#include #include #include 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.