To begin, your code looks horrible.
It looks horrible because of your inexperienced and disordered style of formatting.
This problem must be addressed first, so I will beautify your code.
Hopefully you could try to adopt this style for yourself.
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
|
#include <iostream>
using namespace std;
bool isPrime(int);
int main()
{
int m, n, i;
cin >> m >> n;
for(i = m; i < n; i++)
{
if (isPrime)
cout << " " << i << " ";
else
break;
}
bool isPrime(int N);
{
int N;
if (N % 2 == 0)
return false;
else
return true;
}
return 0;
}
|
Now it is easier to see some of the things that are wrong with the program.
You do not have a
isPrime() function. On lines 4 and 21 you declare it, but you don't define it.
Line 21 contains a declaration because the function's name is followed by a semicolon
;
.
So what starts at line 23 is not a body for a function, it is just a block inside the
main() function. You can have as many blocks as you want.
1 2 3 4 5 6 7 8
|
int main()
{
{
{
int i;
}
}
}
|
However, you may not define a function inside another function, so your
isPrime() must be written outside
main().
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
|
#include <iostream>
using namespace std;
bool isPrime(int);
int main()
{
int m, n, i;
cin >> m >> n;
for(i = m; i < n; i++)
{
if (isPrime)
cout << " " << i << " ";
else
break;
}
return 0;
}
bool isPrime(int N) // removed ;
{ // now we have a body!
// int N; // why does this local variable exist?
if (N % 2 == 0)
return false;
else
return true;
}
|
Now we must fix the
isPrime() function.
How do you check if a number is prime? It is not enough that you check if it divides exactly by 2 (which is what you do right now).
You need to divide N by 2, 3, 4, 5, 6 and so on, until a certain number. Which is ...?
If you can tell me what is that certain number, I'll help you further.