My problem is somewhere in the definition of first_x
and second_x
. When I call the quad_eq
function, I get a -nan(ind) return based on the code below. If I change the .pushback()
method parameter to be a literal integer, I get that integer returned instead of NaN. This leads me to believe that the problem is with my calculation/definition of first_x
and second_x
. Maybe there is some trick to C++ that I am not seeing or understanding. Can anyone see what my problem is? (If this helps I am working out of Bjarne Stroustrup's C++ Principles and Practice Using C++ where he gives me the std_lib_facilities.h file to use as I do not understand headers yet)
vector<double>quad_eq(double a, double b, double c) {
vector<double>answers;
double first_x = (-b + sqrt((b * 2) - (4 * a * c))) / 2 * a;
double second_x = (-b - sqrt((b * 2) - (4 * a * c))) / 2 * a;
answers.push_back(first_x);
answers.push_back(second_x);
return answers;
}