Program keeps crashing on me
I'm trying to write a program that prompts the user to enter the coefficients of a quadratic equation ax^2 + bx + c. This is what I have written so far. The program compiles and runs, but after entering in any coefficients it gives me outputs of root 1.#INF00 and -1.#INF00? Can anyone help me understand why this is? Thanks a bunch. Also, it doesn't crash on me, sorry about that.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(int argc, char **argv)
{
double a;
double b;
double c;
double root01;
double root02;
double quadSqRt = (pow(b, 2.0) - 4.0 * a * c);
printf("Please input the coefficient (a) of x^2 the quadtratic equation:\n ax^2 + bx + c\n");
scanf("%lf", &a);
printf("Please input the coefficient (b) of x the quadtratic equation:\n ax^2 + bx + c\n");
scanf("%lf", &b);
printf("Please input the constant (c) of the quadtratic equation:\n ax^2 + bx + c\n");
scanf("%lf", &c);
if (a != 0 && quadSqRt >= 0){
root01 = (-b + pow(quadSqRt, 0.5)) / (2 * a);
root02 = (-b - pow(quadSqRt, 0.5)) / (2 * a);
} else if (a != 0){
printf("Error: One or more root of the equation are imaginary.");
} else if (a == 0){
printf("Error: a cannot equal 0");
} else {
printf("Bad inputs, please enter again.");
}
printf("The roots are %f and %f", root01, root02);
return 0;
}