#include <iostream.h> //header file for cin cout keyboard input/output 
#include <math.h> //header file for sqrt square root function
/* Free Microsoft Visual C++ source code for college computer sciences homework help. This C programming code provided by 
http://www.homework-help.us. Students,learn from this code,review the computer programming structures and digest the logical flow as if you were writing 
the code.This is the mental process you must duplicate to be a successful computer programmer.For additional help,visit www.homework-help.us to email your request or call Dwayne (757)729-3969
Duplications or derivatives of this code are allowed provided that all above credits and comments are left unmodified.

Inputs: keyboard, 3 coefficients A,B and C of the quadratic equation form Ax2 + Bx + C =0.  
Outputs: Screen, real or imaginary solutions using the quadratic equation formula.
Compiler: Microsoft Visual C++ 6.0
*/		

void main() {

float a,b,c,r1,r2; // declare c++ variables of type float
char ch;
bool more = true;
cout<<"This free resource provided by www.homework-help.us "<<endl<<endl;
cout<<"AX2 + BX + C = 0"<<endl<<endl;        
while(more){	

	cout<<"Enter Coefficient A "<<endl; //keyboard output prompt
	cin>>a;//console input of float variable
	cout<<"Enter Coefficient B "<<endl;//keyboard output prompt
	cin>>b;//console input of float variable
	cout<<"Enter Coefficient C "<<endl;//keyboard output prompt
	cin>>c;//console input of float variable
	cout<<endl<<"Equation "<<a<<"X2 "; // output equation
	if( b >0) //if positive coefficient, output '+' symbol
		cout<<"+ ";
	cout<<b<<"X ";
	if (c >0)//if positive coefficient, output '+' symbol
		cout<<"+ ";
	cout<<c<<" =0"<<endl<<endl;
		

	if((b*b-4*a*c) <0 ) { //quadratic equation discriminant test for imaginary solutions
	float real= -b/(2*a); // real x component
	float imag=sqrt(-(b*b-4*a*c))/(2*a); // imaginary y component
	cout<<"Imaginary Root is "<<real<<" + "<<imag<<" i"<<endl;// output roots in a + bi notation
	cout<<"Imaginary Root is "<<real<<" - "<<imag<<" i"<<endl;
	}
	else
	{ // real solutions from quadratic equation
		r1=(-b+ sqrt(b*b-4*a*c)) /(2*a);
		r2=(-b- sqrt(b*b-4*a*c)) /(2*a);
		cout<<"Real Root 1 is "<<r1<<endl;
		cout<<"Real Root 2 is "<<r2<<endl;
	}

cout<<"Continue ? Enter Y (enter any other character to exit) "<<endl;
cin>>ch;
if( !((ch=='y') || (ch=='Y'))  )
	more=false; 	
}// end while continue 
cout<<"Program comments at http://homework-help.us/phpBB2/index.php. "<<endl;
cout<<"Thank You!"<<endl;

}



