undefined reference to 'isPrime()'

I dont know whats wrong with my code. Basically I need to write a boolean function which take an interger as an arguement and returns true if the arguement is a prime number, and false otherwise and it prints out all the prime numbers between 0 and 100


include<iostream>
using namespace std;

bool isPrime();

int main() {

cout << endl << endl;
cout << " Prime Numbers " << endl;
cout << "---------------------" << endl;

isPrime(int val);

return 0;
}

bool isPrime(int val) {
for(int i = 2, val = 0; val > 0; val++) {
if(val % i == 0) {
cout << val << " is a prime number. " << endl;
return true;
}
else {
return false;
}
}
}



I need help on this i dont understand what im doing wrong
Your declaration

 
bool isPrime();


does not match your definition:

 
bool isPrime(int val) //... 

Also, you're isPrime function does not do what one would expect.

I would expect it to return true or false if the passed number is prime. Instead it loops through all numbers and prints messages to the screen if they're prime.

And you're calling it incorrectly.
jssmith has already answered your question however...
In addition to what has been said, you need to assign an integer value to the variable val which needs to be declared as well before calling the function. Also you are trying to do too much in your isPrime() function and too little in main(). Hint: print the message in main after returning true or false from isPrime()
include<iostream>
using namespace std;

bool isPrime(int);

int main() {

int val;
cout<<"Enter a Prime Number";
cin>>val;
bool prime=isPrime(int val);
return 0;
}

bool isPrime(int val)
{
int count;
for(int i=1;i<=val;i++)
{
if(val%i==0)
{
count++;
}
}
if(count==2)
return true;
else
return false;
}
@vsaurabh2:

We don't just give solutions to homework assignments. Fortunately your implementation is the second
most inefficient solution that I can think of (the first being looping on the condition i <= sqrt( val ),
forcing the evaluation of sqrt( val ) every time through the loop) so I don't think OP will be able to use
it.
Topic archived. No new replies allowed.