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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
using namespace std;
int main() {
double a;
double b;
double c;
double discriminant = 0;
double x1;
double x2;
double i1;
double z1;
int i;
for (i = 1; i < 5 ; i++)
{
cout << "RUN# " << i << endl;
cout << "This program will provide solutions for an equation of the form" << endl;
cout << right << " A*x^2 + B*x + C = 0," << endl;
cout << "where A, B, and C are integers, and A is not equal to zero.\n" << endl;
cout << "Enter A, B, and C: ";
cin >> a >> b >> c;
discriminant = pow(b,2) - (4*a*c);
if (a == 0)
{
cout << "\nNo Solutions will be calculated for a leading coefficient of 0!" << endl;
cout << "-----------------------------------------------------";
cout << endl << endl << endl;
}
else if (discriminant > 0)
{
cout << fixed << showpoint << setprecision(4) << scientific;
x1 = ((-b) + sqrt(discriminant)) / (2 * a);
x2 = ((-b) - sqrt(discriminant)) / (2 * a);
cout << "The two real solutions are x1 = " << x1 << endl;
cout << " and x2 = " << x2 << endl;
cout << "-----------------------------------------------------";
cout << endl << endl << endl;
}
else if (discriminant < 0)
{
cout << fixed << showpoint << setprecision(4) << scientific;
x1 = - (b / (2 * a));
z1 = abs(discriminant);
i1 = sqrt(z1) / (2*a);
cout << "The two imaginary solutions are x1 = " << x1 << " + " << i1 << "*i" << endl;
cout << " and x2 = " << x1 << " - " << i1 << "*i" << endl;
cout << "-----------------------------------------------------";
cout << endl << endl << endl;
}
else if (discriminant == 0)
{
cout << fixed << showpoint << setprecision(4) << scientific ;
x1 = - (b / (2 * a));
cout << "The one real solution is x = " << x1 << endl;
cout << "-----------------------------------------------------";
cout << endl << endl << endl;
}
}
return 0;
}