0

Could you tell me what is wrong?

#include <stdio.h> #include <math.h> double a,b,c; double d= b * b - 4 * a * c; int main() { printf("Enter a, b and c: "); scanf("%lf %lf %lf", &a, &b, &c); if (a == 0) { double x; x = -c/b; printf("x= %2f\n",x); } else if(d>0) { double x1; x1 -= -b + sqrt(d) / (2 * a); double x2; x2 = -b - sqrt(d) / (2 * a); printf("x1=%lf\nx2=%lf", x1, x2); } else printf("It won't work"); return 0; } At the moment it doesn't even compile. The output is: /usr/bin/cmake --build /mnt/c/Users/radbi/CLionProjects/untitled4/cmake-build-debug --target untitled4 -- -j 4 [ 50%] Building C object CMakeFiles/untitled4.dir/main.c.o /mnt/c/Users/radbi/CLionProjects/untitled4/main.c:5:15: error: initializer element is not constant double d= b * b - 4 * a * c; ^ CMakeFiles/untitled4.dir/build.make:62: recipe for target 'CMakeFiles/untitled4.dir/main.c.o' failed make[3]: *** [CMakeFiles/untitled4.dir/main.c.o] Error 1 CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/untitled4.dir/all' failed make[2]: *** [CMakeFiles/untitled4.dir/all] Error 2 CMakeFiles/Makefile2:79: recipe for target 'CMakeFiles/untitled4.dir/rule' failed make[1]: *** [CMakeFiles/untitled4.dir/rule] Error 2 Makefile:118: recipe for target 'untitled4' failed make: *** [untitled4] Error 2

20th Oct 2018, 2:30 PM
Radosław Biedrzycki
Radosław Biedrzycki - avatar
2 Respostas
+ 1
Hello. I'm not sure but I think the problem is that d=b*b-4*a*c but a, b, c haven't a value.
20th Oct 2018, 3:07 PM
Timo Heinzelmann
Timo Heinzelmann - avatar
0
instead of defining the expression of d in global scope just define d in global scope then after Ur first scanf statement type d = " Ur expression "
20th Oct 2018, 4:14 PM
Jitendra
Jitendra - avatar