All pastes #179825 Raw Edit

Stuff

public cpp v1 · immutable
#179825 ·published 2006-09-22 15:44 UTC
rendered paste body
/*	Lab2_2	Solves Quadratic Equations	Using the following definitions;		ax^2 + bx + c = 0	discriminant (d) = b^2 - 4ac	Inputs; a, b, c	Outputs; Root1, Root2	P Norwood	25 September 2006*/#include <iostream>#include <math.h>// may require seperate library, math? for more complex math functions, ie exponentsusing namespace std;int main(){	double a, b, c, x, d, r1, r2;	cout << "Press Return After Entering a Number\n";	cout << "Enter a value for 'a'\n";	cin >> a;	cout << "Enter a value for 'b'\n";	cin >> b;	cout << "Enter a value for 'c'\n";	cin >> c;	cout << "The equation you have supplied is: "		<< "("<< a << "x" << ")" << "^2 + " << b << "x" << " + " << c << "\n";	d = (b*b) - (4*(a*c));	if (d < 0)	{		cout << "The Discriminant Was Less Than 0. There Are No Real Roots, Only Imaginary.\n";	}	if (d == 0)	{		r1 = ((-b) / 2*a);		cout << "There Is One Real Root: " << r1 << "\n";	}	if (d > 0)	{		r1 = ((-b) + sqrt (d)) / (2*a);		r2 = ((-b) - sqrt (d)) / (2*a);		cout << "There Are Two Real Roots.\n Root One: " << r1 << "\n Root Two: " << r2 << "\n";	}	return 0;}/*Sample Run 1Press Return After Entering a NumberEnter a value for 'a'3Enter a value for 'b'1Enter a value for 'c'5The equation you have supplied is: (3x)^2 + 1x + 5The Discriminant Was Less Than 0. There Are No Real Roots, Only Imaginary.Sample Run 2Press Return After Entering a NumberEnter a value for 'a'2Enter a value for 'b'4Enter a value for 'c'2The equation you have supplied is: (2x)^2 + 4x + 2There Is One Real Root: -4Sample Run 3Press Return After Entering a NumberEnter a value for 'a'1Enter a value for 'b'5Enter a value for 'c'2The equation you have supplied is: (1x)^2 + 5x + 2There Are Two Real Roots. Root One: -0.438447 Root Two: -4.56155*/