title: 2nd degree polynomial calculator's output is inconsistent
body: <p>The following code is supposed to read the 3 coefficients of a 2nd degree equation and output the discriminant and the solutions (if there are any) similar to this online calculator: <a href="https://calculator.tutorvista.com/math/496/2nd-degree-equation-calculator.html" rel="nofollow noreferrer">https://calculator.tutorvista.com/math/496/2nd-degree-equation-calculator.html</a>
  But for some reason my calculator seems to get some results correctly in some cases but not most of them.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;math.h&gt;
  
  using namespace std;
  
  int main() {
  
      float a, b, c;
  
      cout &lt;&lt; "a=" &lt;&lt; endl;
      cin &gt;&gt; a;
      cout &lt;&lt; "b=" &lt;&lt; endl;
      cin &gt;&gt; b;
      cout &lt;&lt; "c=" &lt;&lt; endl;
      cin &gt;&gt; c;
  
      float delta = (pow(b, 2)) - (4 * a*c);
      float summit = (-b) / (2 * a);
      float x1 = (-(b) + (sqrt(delta)) / (2 * a));
      float x2 = (-(b) - (sqrt(delta)) / (2 *a));
  
  
  
      cout &lt;&lt;"Discriminant="&lt;&lt; delta &lt;&lt; endl;
  
      if (delta &lt; 0) {
          cout &lt;&lt; "No solution" &lt;&lt; endl;
      }
      else if (delta == 0) {
          cout &lt;&lt; "Unique solution is:" &lt;&lt; summit &lt;&lt; endl;
  
      }
      else {
          cout &lt;&lt; "First solution is:" &lt;&lt; x1 &lt;&lt; endl;
          cout &lt;&lt; "Second solution is:" &lt;&lt; x2 &lt;&lt; endl;
  
      }
      std::cin.ignore();
      std::cin.get();
  }
  </code></pre>
  
  <p>Here are some rare input examples where my calculator works as intended,according to the online calculator linked above:</p>
  
  <p>a=3;b=1;c=24;</p>
  
  <p>a=1;b=0;c=0;</p>
  
  <p>a=1;b=-4;c=4;</p>
  
  <p>But things don't always go so smoothly,for example inputting 1;4;-12 gives you 8 and 0 as opposed to  6 and -2 (notice how the results are off by 2),in other cases one of the solutions would be correct while the other won't,and most of the time the reults are completely off.</p>
  
  <p>I'm not exactly sure if the problem is from the discriminant or the solution,because sometimes the former would be correct while the latter isn't.</p>
  
  <p>Is there a certain etiquette when it comes to writing mathematical formulas in C++ that I'm not aware of?</p>
  
  <p>Thanks in advance.</p>