Why doesn't my quadratic equation work?

#include
#include

int main() {

double a, b, c;

//finding variable a, b, c
std::cout << “Enter a:\n”;
std::cin >> a;

std::cout << “Enter b:\n”;
std::cin >> b;

std::cout << “Enter c:\n”;
std::cin >> b;

//finding two variables to store the roots of the quadratic equation
double root1, root2;
root1 = (-b + std::sqrt(b * b - 4 * a * c)) / (2 * a);
root2 = (-b - std::sqrt(b * b - 4 * a * c)) / (2 * a);

//output these values
std::cout << "root 1 is " << root1 << “\n”;
std::cout << "root 2 is " << root2 << “\n”;

}

Every time I input the values 6, -7, -3 into my quadratic equation, the roots come out to be
root 1: 0.5
root 2: 0

when it should be
root 1: 1.5
root 2: -0.33333

what did I input wrong? I can’t figure it out for the life of me

See anything amiss, here?

1 Like