Feb 10, 2018 at 3:32pm UTC
Hi!
I have two errors from the code below at the lines starting with int idx:
"invalid use of member (did you forget the &?)"
and on the line starting with out=/
"idx was not declared in this scope"
Can anyone kindly help?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <algorithm>
double QCalc(std::vector<double > x, std::string method) {
double alpha = 0.99;
double alpha_tilde = 0.974234518211730;
double out = 0.;
std::sort(x.begin(), x.end());
if (method == "quantile" ) {
int idx = std::ceil((1. - alpha) * x.size());
out = x[idx];
} else if (method == "ETL" ) {
int idx = std::ceil((1. - alpha_tilde) * x.size());
for (int i=0; i<=idx; ++i) {
out += x[i];
}
out /= idx + 1;
}
return out;
}
Last edited on Feb 10, 2018 at 3:38pm UTC
Feb 10, 2018 at 3:45pm UTC
You wrote: double out = 0. ;
Remove the . or make it 0.0 and your code should compile fine.
Feb 10, 2018 at 3:48pm UTC
What other #include files are you using?
Your snippet appears to be missing several required #includes.
Feb 10, 2018 at 3:49pm UTC
Hi, I did but still get the same errors
Last edited on Feb 10, 2018 at 3:49pm UTC
Feb 10, 2018 at 4:46pm UTC
Take jlb's advice. Your code will compile just fine if you add the three missing #include directives. Hint: you need the #includes that define std::vector, std::string and std::ceil