Hi!
I am new to this website and Ive seen many prime number questions asked but none about my specific problem. It may sound simple but Ive tried everything and just can not get past two syntax errors! Please and Thank You for helping!!!
Here is my code:
#include<iostream>
#include<cmath>
using namespace std;
bool prime(double num, int j);
int main()
{
double num = 10000;
for (int j = 3; j <= 10000; j++)
{
bool prime(double num, int j);
if (bool prime (double num, int j)) // error one is here (?)
{ // error two is actually on this line (yes
cout << " " << j << " "; // the bracket) (??)
}
}
return 0;
}
bool prime(double num, int j)
{
bool prime = true;
for(int i = 2; i <= sqrt(num); i++)
{
if(i % 2 == 0)
i++;
When you call a function, you only pass the arguments. You don't need to also provide the types of the arguments, nor the function's return type: if (prime(num,j))
EDIT: Sometimes you do need to specify what type an argument is: when the function is overloaded and an argument could be interpreted as one of several types.
You're not returning false at any point. What he means by it "unconditionally returns true" is that you've hard-coded "return true". So no matter what happens; if pigs fly, it won't return false.
I think on the return statement you want to return "prime".
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
bool prime(double num, int j)
{
bool prime = true;
for(int i = 2; i <= sqrt(num); i++)
{
if(i % 2 == 0)
i++;
if((int(num % i)) == 0)
{
prime = false;
break;
}
}
return prime;
}