Apr 3, 2012 at 9:12pm UTC
Ok guys, i think that the title of the post says everything.
My problem is that my program is supposed to solve a quadratic equation but the second zero of the equation is -1.#IND always, no matter what are the number inserted :S
Help please, here is the code!
{
system("CLS");
std::cout << "a=";
double a;
std::cin >> a;
std::cout << "b=";
double b;
std::cin >> b;
std::cout << "c=";
double c;
std::cin >> c;
system ("CLS");
double bd;
bd = (b*b)-(4*a*c);
if (bd>0) {
double result1;
result1 = sqrt(-b+bd)/(2*a);
double result2;
result2 = sqrt(-b-bd)/(2*a);
std::cout << "x= " << result1 << " V " << "x= " << result2 << std::endl;
system("pause");
system("CLS");
}
else if (bd<0) {
std::cout << "Impossible Equation in R" << std::endl;
system("pause");
system("CLS");
}
Apr 4, 2012 at 12:14am UTC
The formula is wrong.
It should be like this:
if (bd >= 0) {
double result1;
result1 = (-b + sqrt(bd))/(2*a);
double result2;
result2 = (-b - sqrt(bd))/(2*a);
}
else {
std::cout << "Complex roots";
}
Apr 4, 2012 at 8:54am UTC
OMG
you're right! Thank you
Works perfectly!
TY once again