I have to make a quadratic equation in Microsoft Visual Studio.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
float a, b, c, D, x1, x2;
printf("Type in a :\n");
scanf_s("%d", &a);
if (a == 0)
{
printf("The equation is not quadratic");
}
else
{
printf("Type in b:\n");
scanf_s("%d", &b);
printf("Type in c:\n");
scanf_s("%d", &c);
D = b*b - 4 * a*c;
if (D < 0)
{
printf("There are no real roots");
}
else if (D == 0)
{
x1 = x2 = -b / (2 * a);
}
else
{
x1 = (-b + powf(D, 0.5)) / (2 * a);
x2 = (-b - powf(D, 0.5)) / (2 * a);
}
}
system("pause");
return 0;
}
This is what I have done till now. Can you tell me where is my mistake? The studio isn't finding any mistakes, but there is a problem - after starting the program I type in a, b, and c and after that it says : "Press any key to continue" and when I do the console window disappears. Pls help