1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;
double quad(double&,double&,double&,double&,double&);
int main()
{
double a;
double b;
double c;
double x1;
double x2;
char choice = 'y';
cout <<"This program will find the roots of a quadratic"<<endl<<endl;
do{
cout <<"Please input the values for the coefficients; a, b, c""(y=ax^2+bx+c)"<<endl<<endl;
cin>>a>>b>>c;
if((b * b - 4 * a * c) > 0);
quad(a,b,c,x1,x2);
cout <<"The positive roots are "<<x1<<endl<<endl;
else if ((b * b - 4 * a * c) == 0)
quad(a,b,c,x1,x2);
else if ((b * b - 4 * a * c) < 0)
quad (a,b,c,x1,x2);
cout <<"The negative roots are "<<x2<<endl<<endl;
system ("cls");
cout <<"Would you like to run this again? y or Y for yes, anything else for no"<<endl<<endl;
}while (choice =='y' || choice =='Y');
system ("Pause");
return 0;
}
double quad(double&a, double&b, double&c, double&x1, double&x2)
{
double x1,x2;
x1 = (-b+sqrt(b*b-4*a*c))/(2*a);
x2 = (-b-sqrt(b*b-4*a*c))/(2*a);
return x1,x2;
}
|