int Count(int q){
q=0;
for (int i1=-3; i1<=3; i1++){
for (int i2=2; i2<i1; i2++){
if (i1%i2!=0){
q+=1;
break;}
}
}
return q;
}
int main-(){
cout<<Count;
return 0;
}
Error: In function 'int main()':
Line 19: warning: the address of 'int Count(int)', will always evaluate as 'true'
Why 'true', there is no "bool" options???
Many thanks!
Count is the name of a function. When used on it's own, it's a pointer to the function, and will always be positive. It will therefore always evaluate to true.
Did you mean to actually call the Count function and yest the return value? If so, then you need to go back to your textbook and look up the correct syntax for calling functions.
1) Your indentation is atrocious. Proper indentation is critical for writing code which can be easily read by others.
2) There is no reason for 'q' to be a parameter for your count function. Parameters are used for passing input to a function.. .since your function will throw away any value passed in for 'q' (since you assign q to 0 right away), there is not point.
3) You have a stray '-' symbol after main.
4) (the actual cause of your compiler warning) When you call a function, you have to give it parenthesis to indicate you want to call the function. Just specifying the function name gives you a pointer to the function, but does not actually execute any of the function's code.
int Count() // <- you do not need any parameters
{
int q=0; // <- make q local to this function instead of a parameter
// fix this insane indentation so the code is readable
for (int i1=-3; i1<=3; i1++)
{
for (int i2=2; i2<i1; i2++)
{
if (i1%i2!=0)
{
q+=1;
break;
}
}
}
return q;
}
int main() // <- get rid of stray '-' symbol
{
cout<<Count(); // <- add parenthesis after Count to indicate you want to call the function
return 0;
}