im having trouble compiling this program. its basically finished but when compiling it fails and gives me the error: line 32 expected expression before 'else.'
I can't seem to find anything wrong with my code or logic, maybe someone here can point it out?
Quote
Following is a sample run:
Enter a: 4.4
Enter b: 5.5
Enter c: 3.3
There are two complex roots:
root1 = -0.62 + j0.60
root2 = -0.62 - j0.60
Your program must meet the following specifications.
• if coefficient a is zero and b is not zero, print "This is a linear equation. The root is ..."
• if both a and b are zero, print "This is not an equation."
• Print all real numbers with 2 digits to the right of the decimal point.
• Be sure to handle the cases where both roots are real (i.e., b2-4ac > 0) and where there is a double real root (i.e., b2-4ac = 0), as well as where there are two complex roots as in the sample run above (i.e., b2-4ac < 0).
• When printing a complex root with negative imaginary part, be sure to put the minus sign before the j. That is, do not print root2 above as -0.62 + j-0.60 .
#include <stdio.h>
#include <math.h>
main ()
{
float a, b, c, d, x, y, root1, root2;
printf("Enter a: ");
scanf("%f", &a);
printf("Enter b: ");
scanf("%f", &B)/>;
printf("Enter c: ");
scanf("%f", &c);
if (a == 0 && b != 0) {
printf("This is a linear equation. The root is: %.2f", -c / B)/>;
} else if (a == 0 && b == 0) {
printf("This is not a quadratic equation.\n");
} else {
d = (b * B)/> - (4 * a * c);
x = -b / (2 * a);
if (d < 0) {
d = d * -1;
y = sqrt(d) / (2 * a);
printf("\nThere are two complex roots:\n");
printf("root1 = %.2f + j%.2f\n", root1, root2);
printf("root2 = %.2f - j%.2f\n\n", root1, root2);
}
} else if (d == 0) {
y = sprt(d) / (2 * a);
root1 = x + y;
printf("There is one root: \n");
printf("root = %.2f\n", root1);
} else if (d > 0) {
y = sqrt(d) / (2 * a);
root1 = x + y;
root2 = x - y;
printf("There are two real roots: ");
printf("root1 = %.2f\n", root1);
printf("root2 = %.2f\n", root2);
}
return 0;
}
Any help or insight will be much appreciated.

New Topic/Question
Reply



MultiQuote



|