Help Formatting output to .txt file

This is my code right now and everything works except for two things. When i read the output to the .txt it does not accurately work for NO REAL ROOTS and i cannot figure out where to put in the if statement i used for the normal output that makes the smaller number appear first.

#include <iostream>
#include <fstream>
#include <cmath>
#include <complex>
#include <string>

using namespace std;

int main()
{
ofstream program4;
program4.open ("program4.txt");

complex <double> x1, x2;
double a, b, c;


cin >> a;

cin >> b;

cin >> c;

x1 = (-b + sqrt(b * b - 4.0 * a * c )) / (2.0 * a);
x2 = (-b - sqrt(b * b - 4.0 * a * c )) / (2.0 * a);

program4 << x1.real() << ", "<< x2.real();

program4.close();

if ( x1 == x2)
cout << x1.real() ;
if ( x1.real() < x2.real())
cout << x1.real() << ", " << x2.real() ;
if ( b < 4.0 * a * c)
cout << "NO REAL ROOTS" << endl;
else
cout << x2.real() << ", " << x1.real() ;

return 0;

}
Topic archived. No new replies allowed.