This is for a class. I am NOT asking for someone to do this for me. I just can't find out an issue and would appreciate it if anyone could point out its cause.
This is the program.
Code:
int main(void)
{
//Variable declaration
double a, b, c, discriminant, r1, r2;
//Display title prompt
printf("This program finds the roots of the quadratic equation.\n");
//Prompt user for coefficients of the quadratic equation
printf("Input the a, b, and c coefficients of the quadratic equation\n in this form: (a)x^2 + (b)x + (c) \n");
//Read user values and assign to appropriate variables
scanf("%dx^2+%dx+%d", &a, &b, &c);
//Find root type
discriminant = (b*b-4*a*c);
//Find roots using the variables and display
if (discriminant>0)
{
r1 = -b+sqrt(discriminant)/(2*a);
r2 = +b+sqrt(discriminant)/(2*a);
printf("The two roots are real: ");
printf("%d %d\n");
}
else if (discriminant==0)
{
r1 = -b+sqrt(discriminant)/(2*a);
r2 = +b+sqrt(discriminant)/(2*a);
printf("The two roots are equal: ");
printf("%d %d\n");
}
else
{
r1 = -b+sqrt(discriminant)/(2*a);
r2 = +b+sqrt(discriminant)/(2*a);
printf("The two roots are complex and may not be correct: ");
printf("%d %d\n");
}
//Termination statements
system ("PAUSE");
return 0;
}
My problem is that, no matter the variables, I always get the last else statement as the answer "The roots are complex...." even when I KNOW they're real or equal. Can't see why. Any help?