loading

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.48297127302644793","path":"main.cpp","file":{"path":"main.cpp","content":{"asEncoding":{"base64":"LyoKIFNvbHZlIHRoZSBxdWFkcmF0aWMgZXF1YXRpb24gZm9yIDQgZGlmZmVyZW50IHNvbHV0aW9ucwogMS4gR2l2ZSBpbnRlZ2VycyBBLEIsIGFuZCBDCiAyLiBTb2x1dGlvbnMKIGEuIGEgaXMgZXF1YWwgdG8gemVybyAobm90IGRlZmluZWQpCiBiLiBkaXNjcmltaW5hbnQgaXMgPCAwIChpLmUuIG5vIHJlYWwgc29sdXRpb25zKQogaS4gZm9yIGFueSBnaXZlbiBpbWFnaW5hciBzb2x1dGlvbnMgbXVsdGlwbHkgdGltZXMgc3RyaW5nIGkgKHdoZXJlIGkgPSBzcXJ0KC0xKSkKIGMuIGRpc2NyaW1pbmFudCBpcyA+IDAgKGkuZS4gcmVhbCBzb2x1dGlvbnMpCiBkLiBkaXNjcmltaW5hbnQgaXMgPSAwIChpLmUuIG9ubHkgb25lIHNvbHV0aW9uKQogKi8KCiAKCiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPGlvbWFuaXA+CiNpbmNsdWRlIDxzdHJpbmc+CiNpbmNsdWRlIDxjbWF0aD4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpIHsKICAgIAogICAgLy9EZWNsYXJhdGlvbiAmIEluaXRpYXRpb25zCiAgICBkb3VibGUgYTsKICAgIGRvdWJsZSBiOwogICAgZG91YmxlIGM7CiAgICBkb3VibGUgZGlzY3JpbWluYW50ID0gMDsKICAgIGRvdWJsZSB4MTsKICAgIGRvdWJsZSB4MjsKICAgIGRvdWJsZSBpMTsKICAgIGRvdWJsZSB6MTsKICAgIAogICAgCiAgICAKICAgIC8vSW5wdXQKICAgIAogICAgCiAgICAKICAgIGludCBpOwogICAgZm9yIChpID0gMTsgaSA8IDUgOyBpKyspCiAgICB7CiAgIC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ICAgY291dCA8PCBlbmRsIDw8IGVuZGwgPDwgZW5kbDsKICAgIH0KICAgIGVsc2UgaWYgKGRpc2NyaW1pbmFudCA9PSAwKSAgICAvLyAxIHNvbHV0aW9uCiAgICB7CiAgICAgICAgY291dCA8PCBmaXhlZCA8PCBzaG93cG9pbnQgPDwgc2V0cHJlY2lzaW9uKDQpIDw8IHNjaWVudGlmaWMgOwogICAgICAgIHgxID0gLSAoYiAvICgyICogYSkpOwogICAgICAgIGNvdXQgPDwgIlRoZSBvbmUgcmVhbCBzb2x1dGlvbiBpcyB4ID0gIiA8PCB4MSA8PCBlbmRsOwogICAgICAgIGNvdXQgPDwgIi0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tIjsKICAgICAgICBjb3V0IDw8IGVuZGwgPDwgZW5kbCA8PCBlbmRsOwogICAgfQogICAgCiAgICAgICAgCiAgICB9CiAgICByZXR1cm4gMDsKfQo="},"asBuffer":null},"loaded":true}}
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
/*
 Solve the quadratic equation for 4 different solutions
 1. Give integers A,B, and C
 2. Solutions
 a. a is equal to zero (not defined)
 b. discriminant is < 0 (i.e. no real solutions)
 i. for any given imaginar solutions multiply times string i (where i = sqrt(-1))
 c. discriminant is > 0 (i.e. real solutions)
 d. discriminant is = 0 (i.e. only one solution)
 */

 

#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>

using namespace std;

int main() {
    
    //Declaration & Initiations
    double a;
    double b;
    double c;
    double discriminant = 0;
    double x1;
    double x2;
    double i1;
    double z1;
    
    
    
    //Input
    
    
    
    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;
    
    //Process & Outputs
    discriminant = pow(b,2) - (4*a*c);
    
    
        
    
    if (a == 0) // no solutions
    {
        cout << "\nNo Solutions will be calculated for a leading coefficient of 0!" << endl;
        cout << "-----------------------------------------------------";
        cout << endl << endl << endl;
    }
    else if (discriminant > 0) // 2 real solutions
    {
        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) // 2 imaginary solutions
    {
        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)    // 1 solution
    {
        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;
}