This question already has an answer here:
I am trying to handle C++ through examples of Numerical Analysis (root finding using different methods)
For this purpose, I would like to loop over an array of initial values and try several methods for each value. I found one way to loop on another topic, but it doesn't totally solve my problem :
int main(int argc, char **argv) {
double init[] = {-2, 3.8, 20, -40};
int N = 5;
for(const double &x : init)
cout << "value of x" << FindRootNewton(x,N) << endl;
cout << "value of x" << FindRootSecant(x,N) << endl;
return 0;
}
I have 2 problems with this code :
-
I have a warning on the line starting the loop (for ...) : range-based for loop is a C++11 extension [-Wc++11-extensions] What does it mean ? I think I have a C++98 compiler, I tried to figure out using __cplusplus macro and the output is 199711L.
-
He can't read the second line of the loop, "use of undeclared identifier x", as if the variable vanished after first use.. But if I comment this second line out, all works fine.
Thanks for any help on this
Aucun commentaire:
Enregistrer un commentaire