Ok it all looks good, but I reckon it fails at link time, even though sqrt() is in math.h you may need to specify it in your compiler command line, it will be a switch of some sort. If you reveal your IDE compiler then I may be able to find out.
He doesn't use s1 or s2 in the else statement. He has s1 and s2 in quotations. I really don't see why you need disc and those if statements. Just do this:
#include <iostream>
#include <math.h>
usingnamespace std;
int main()
{
// Initializations and input here.
s1 = -b + sqrt((b * b - 4 * a * c) / (2 * a));
s2 = -b - sqrt((b * b - 4 * a * c) / (2 * a));
if(s1 != s1 || s2 != s2) // If the result is an imaginary number.
{
cout << endl << "The result is an imaginary number." << endl;
}
else // If the result is NOT an imaginary number.
{
cout << endl << "s1 = " << s1 << endl;
cout << "s2 = " << s2 << endl;
}
system("pause");
return 0;
}
For complex roots, you seem to be outputting the equation for computing the imaginary parts, not the computed numbers.
Also, you seem to be outputting results twice.
Say disc is negative.
Then the third if condition executes and you output the complex results.
But then after the program has passed through these three checks, you output s1 and s2 right before program termination.
Same thing if disc > 0.
You output s1 and s2 in the if condition, and then again right before program termination.