I'm making a program so that it solves quadratic equations (ax^2 + bx + c), bu it doesn't give me any response...
I wrote this:
#include <iostream>
using namespace std;
int main()
{
double a, b, c, r1, r2, delta;
//int a, b, c;
cout << "Introduza os coeficientes (a b c) ";
cin >> a >> b >> c;
delta = pow (b,2) - (4*a*c);
if (delta > 0)
{
r1 = (-b + sqrt(delta))/(2*a);
r2 = (-b - sqrt(delta))/(2*a);
cout << "A equação tem 2 raizes reais: " << r1 << " e " << r2 << endl;
}
if (delta = 0)
{
r1 = (-b)/(2*a);
cout << "A equação tem 1 unica raiz: " << r1 << endl;
}
if (delta < 0)
{
r1 = (-b)/(2*a) + (sqrt (-delta)/(2*a));
r2 = (-b)/(2*a) - (sqrt (-delta)/(2*a));
cout << "A equação tem 2 raizes complexas conjugadas: " << r1 << "i e " << r2 << "i " << endl;
}
return 0;
}
The case in which "delta > 0" is perfectly done, it gives me the right answer, but the other two cases, doesn't give any response at all! I can't find my mistake, can you help me please?