Professional Documents
Culture Documents
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
/*
Aim of the program : To find the roots of a quadratic equation
*/
/* ******************
Preprocessor directives
*********************** */
#include <iostream>
#include <cmath>
using namespace std;
/* ******************
Other functions
*********************** */
*********************** */
int main()
{
// Stores plenty of info and calculations
double a,b,c,D,x1,x2;
// Used to ask the user whether to continue
char chrCont;
cout<<"\t\t\tExperiment 1.7:
lblBeg:
cout<<"Please enter the coefficient of x^2: ";
cin>>a;
cout<<"Please enter the coefficient of x: ";
cin>>b;
cout<<"Please enter the constant: ";
cin>>c;
cout<<"The equation is:\n"<<a<<"x^2 + "<<b<<"x + "<<c<<endl;
D = b*b - 4*a*c;
if (D > 0)
{
x1 = -b/(2*a);
x2 = sqrt(D)/(2*a);
cout<<"Its roots are real and distinct, given by "<<x1+x2<<" and "<<x1-x2;
}
else if (D==0)
{
x1 = -b/(2*a);
cout<<"Its roots are real and equal, given by "<<x1;
}
else
{
x1 = -b/(2*a);
x2 = sqrt(-D)/(2*a);
cout<<"Its roots are imaginary, given by "<<x1<<" + i"<<x2<<" and "<<x1<<" - i"<<
x2;
60
61
62
63
64
65
66
67
68
69
}
cout<<"\nDo you wish to try again? (y-Yes)";
cin>>chrCont;
if(chrCont=='y' || chrCont == 'Y') goto lblBeg;
return 0;
}