Hello all, I'm at that lovely time in a mathematical learning experience in which you are forced to submit to memorizing the quadratic formula, which is not only despicably confusing but long and painful to work with. I decided to write a program that would do quadratic equations for me, and the final code (debugged and everything) is as follows:
All right, so after compiling and running this I percieve no warnings or errors from the compilers, but after entering the first number and pressing enter, it says that the program has performed an illegal operation. Why?Code:#include <stdio.h>
#include <stdlib.h>
#include <math.h>
float a;
float b;
float c;
float d;
float e;
float f;
int main()
{
printf("The format for a quadratic equation is ax^2+bx+c=0.\n");
printf("This should solve a quadratic equation.\n");
printf("Enter the A variable.\n");
scanf("%f",a);
printf("Enter the B variable.\n");
scanf("%f",b);
printf("Enter the C variable.\n");
scanf("%f",b);
if(2*a!=0)
{
d=sqrt(b*b-4*a*c);
e=(-b+d)/(2*a);
f=(-b-d)/(2*a);
printf("X equals %f and %f.\n",e,f);
}
else
{
printf("No real number solution.\n");
}
system("PAUSE");
return 0;
}
Thanks a lot
Raytro2