I dont know the error for the code

Hey Guys,
I tried to develop a simple Program which finds out a number is prime or composite, but the program always return composite, I dont know what is the problem, can anyone find out what is the error?

//--------------Main.cpp ---------------------

using namespace std;

int main()
int number, result;
number = get_num();
result = prime_func(number);
cout<<"The Entered number is PRIME.\n";
cout<<"The Entered Number is COMPOSITE.\n";

return 0;

#include "declare.h"

using namespace std;

int get_num()
int num;
cout<<"Please Insert a number: ";
return num;
bool prime_func(int p_num)
int div_rem;
for(int i=2; i<=(p_num-1); i++)
div_rem = p_num%i;
return false;
return true;
if(result=='1') you're comparing with the literal '1' which is not the number 1, instead the value is 49.

if you use bool you should always use true/false as well.

Please use code tags: [code]Your code[/code]
See: http://www.cplusplus.com/articles/jEywvCM9/
Thanks for your comments, coder777 sorry i didnt put my code in tags cause i am new to this website, the problem did not solve yet i think it has mathematical and logical problem but i dont know where?
ne555 if i dont include *.cpp file, the program will get error and will not run.

same mistake here: if(div_rem=='0')
again you don't compare with 0 instead the literal '0' (which 48).

Be careful that you don't confuse numbers and literals
Coder777, Thanks for your Help man i got it solved. Thanks so muchhhh for your help ;)
> if i dont include *.cpp file, the program will get error and will not run.
`I've got an error' is not an error message.

<nolyc> Undefined reference is a linker error.
It's not a compile error. #includes don't help. [*]
You did not define the thing in the error message, you forgot to link the file that defines it, you forgot to link to the library that defines it, or, if it's a static library, you have the wrong order on the linker command line.
Check which one. (Note that some linkers call it an unresolved external)


[*] You are not supposed to put function definitions in header files (risk of `multiple definition')
However there are two exceptions: inline and template.
Last edited on
Use code format.
Topic archived. No new replies allowed.