// if_quadratic_equation.cpp
//
#ifdef _WIN32
	#include <tchar.h>
	#include <conio.h>
#elif (defined __linux__) || (defined _AIX) || (defined __APPLE__)
	typedef char _TCHAR;
	#define _tmain main
#endif

#include <stdio.h>
#include <math.h>
#include <iostream>
using namespace std;

void my_getch();

int _tmain(int argc, _TCHAR* argv[])
{
	float a, b, c, d, xr1, xr2, xi;

	cout << "\nZadajte koeficienty a,b,c kvadratickej rovnice"
		<< " a*x^2 + b*x + c = 0." << endl;
	cout << "a = ";
	cin >> a;
	cout << "b = ";
	cin >> b;
	cout << "c = ";
	cin >> c;

	cout << endl << "Riesenia rovnice su:" << endl;
	if (a == 0) {
		if (b == 0) {
			if (c == 0)
				cout << "  nekonecne vela rieseni";
			else
				cout << "  ziadne riesenie";
		}
		else
			cout << "  x = " << -c / b;
	}
	else {
		d = b * b - 4 * a * c;
		if (d >= 0) {
			xr1 = (-b + sqrt(d)) / (2 * a);
			xr2 = (-b - sqrt(d)) / (2 * a);
			xi = 0;
		}
		else {
			xr1 = -b / (2 * a);
			xr2 = xr1;
			xi = fabs(sqrt(-d) / (2 * a));
		}
		cout << "  x1 = " << xr1 << "+i*" << xi << endl;
		cout << "  x2 = " << xr2 << "-i*" << xi << endl;
	}

	my_getch();
	return 0;
}

void my_getch()
{
#ifdef _WIN32
	_getch();
#else
	cout << endl;
#endif
}