I am supposed to write a program that asks for the coefficients a, b, and c of a quadratic equation ax2+bx+c=0. It needs to display to the screen one of the following:
• two distinct real numbers (when b2-4ac > 0),
• two distinct complex numbers (when b2-4ac < 0), or
• one real number (when b2-4ac = 0)
I have worked the following program and it doesn't work when set up this way:
#include <iostream>
using namespace std;
int main()
{
cout << "Enter three integers and the product will be displayed: ";
cin >> a >> b >> c;
if (((b * b) - (4 * a * c)) > 0)
cout << "The result of " << a << "," << b << ", and\n "
<< c << " has two distinct real numbers.";
else if (((b * b) - (4 * a * c)) < 0)
cout << "The result of " << a << "," << b << ", and\n "
<< c << " has two distinct complex numbers.";
else (((b * b) - (4 * a * c)) == 0)
cout << "The result of " << a << "," << b << ", and\n "
<< c << " has one real number.";
system ("pause");
return 0;
}
If I change the last statement to 'if else' the program works, but I don't think that would be correct. Please help.