I've been looking over this problem I have for my programming class, and quite honestly, I can't figure out how I should write this quadratic equation.
In case anyone reading this doesn't know, quadratic equation is :
x = (-b +- sqrt((b^2)-4ac))/2a
Now my question is, how would I put that into C++ in my program? (I haven't started it yet because I want to figure out how to write this equation into it first)
#include <iostream.h>
#include <cmath>
int main ()
{
//Declare Variables
double x,x1,x2,a,b,c;
cout << "Input values of a, b, and c." ;
cin >>a >>b >>c;
for (int i = 1; i <= 10; ++i);
{
if ((b * b - 4 * a * c) > 0)
cout << "x1 = (-b + sqrt(b * b - 4 * a * c)) / (2 * a)" &&
cout << "x2 = (-b + sqrt(b * b - 4 * a * c)) / (2 * a)";
ifelse ((b * b - 4 * a * c) = 0)
cout << "x = ((-b + sqrt(b * b - 4 * a * c)) / (2 * a)"ifelse ((b * b - 4 * a * c) < 0)
cout << "x1 = ((-b + sqrt(b * b - 4 * a * c) * sqrt (-1)) / (2 * a) &&
cout << "x2 = ((-b + sqrt(b * b - 4 * a * c) * sqrt (-1)) / (2 * a);
}
return (0);
}
Well...that's what I can come up with so far...the handout from our teacher (I think) very vaguely explained how to code it if the discriminant (b*b - 4*a*c) < 0, so I just input it as I thought it would work.
If anyone could look over this and point out necessary adjustments I need to make, it would be much appreciated.
Well, I think I realized some stupid mistakes I made, but I'll just see what kind of input I get.