problem when compiling a program

Hi, guys! I'm new to C++ programming and I'm currently using Linux.
I wrote this program(that checks if a number is prime or not):

#include <iostream>
using namespace std;

bool isprime(int);
int main()

{
int num;
do {
cout << "Please enter a number to check whether the number you entered is prime or not(press 0 to stop):\n";
cin >> num;

for ( num = 0;num > 0; num++) {
if (isprime(num) == true) {
cout << num << " is a prime number.\n";
}

else {
cout << num << " is not a prime number.\n";
}
if ( num = 0) {

}
}

} while ( num > 0);
return 0;
}

bool isprime(int x, int y)

{
if ( x < 2 ) {
return false;
}
else if ( x > 2 && ( x % 2) == 0) {
return false;
}

for ( int i = 2; i <= x/2; i++ ) {
if ( x % i == 0) {
return false;
}
}
return true;
}
When I try to compile it with g++,I get this error:In function `main':
perfect.cpp:(.text+0x43):undefined reference to `isprime(int)'
collect2: ld returned 1 exit status.
Please help me find out what's wrong in my program so I can fix the problem.
Thanks in advance!




You really just need to read your code! There are a few very obvious mistakes if you just walk through it.

If nothing stands out immediately, walk through the code for a few test values.

Finally, where in you code have you declared the missing function: isprime(int) ???
Thank you very much! I figured it out and now my program works .
Topic archived. No new replies allowed.