• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

C++ Programming Question

I compile my program, and I get these errors:

program19.cpp: In function `void generateSieve(bool*, int)':
program19.cpp:63: call of overloaded `sqrt(int)' is ambiguous
/usr/include/bits/mathcalls.h:157: candidates are: double sqrt(double)
/usr/include/c++/3.2.2/cmath:465: long double std::sqrt(long
double)
/usr/include/c++/3.2.2/cmath:461: float std::sqrt(float)


Here is the code involved:
 
it looks like in your outer for loop you are taking the square root of an int, and it can't decide whether to cast it as a float, doublt, or a long double. plus, you are comparing the output of it (a floating point number) with an int, which you should becareful about.

here's a tip to help, since you comparison is against a fixed number (sqrt(sievesize-1)), move that to before the loop starts, that way you aren't calculating it repeatedly.

hope that helps
 
I got the program to compile. However, now it is giving this error, and my teacher's submition program is saying it won't be graded unless this error is removed.

program19.cpp: In function `void generateSieve(bool*, int)':
program19.cpp:65: warning: statement with no effect

Here is the new code I made:
 
You're getting that warning (it's not an error) because the line:

static_cast<int>(temp);

does absolutely nothing.
 
the error was with the cast..
static_cast<int>(temp);
is a statement with no effect. the variable temp was declared as a double, you can't change that but u can cast it to another int variable.
 
Back
Top