title: Why does program output x1 = Nan, x2 = Nan?
body: <p>I can't work out why my program isn't doing what it's supposed to do. The task was to make a c program that can solve quadratic using two c files. This is the code called interface.c that we got to work with, nothing has to be changed on this one:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  void abc (void);
  
  int a, b, c;
  
  extern double x1real, x1imag, x2real, x2imag;
  
  static void get_parameters (void)
  {
      scanf("%d", &amp;a);
      scanf("%d", &amp;b);
      scanf("%d", &amp;c);
  }
  
  void print_solution(void)
  {
      printf("The roots of %dx^2 + %dx + %d are:\n",a,b,c);
  
      if(x1imag == 0 &amp;&amp; x2imag == 0)
      {
          if(x1real == x2real)
          {
              printf("x = %.4f\n", x1real);
          }
          else
          {
              printf("x1 = %.4f, x2 = %.4f\n", x1real, x2real);
          }
      }
      else
      {
          printf("x1 = %.4f+%.4fi, x2 = %.4f-%.4fi\n", x1real, x1imag, x2real, x2imag);
      }
  }
  
  int main (void)
  {
      int runs, run;
  
      scanf("%d",&amp;runs);
  
      for(run=0; run &lt; runs; run++)
      {
          get_parameters();
          abc();
          print_solution();
      }
  
      return 0;
  }
  </code></pre>
  
  <p>Next is the code I made which isn't working, there seems to go something wrong with the integer types I think. With every quadratic formula it will output x1 = nan x2 = nan. There is something wrong with the integer type but can't figure out which.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;math.h&gt;
  #include &lt;stdlib.h&gt;
  
  extern int a, b, c;
  
  double x1real, x1imag, x2real, x2imag;
  
  int discriminant(void)
  {
      int discriminant;
  
      discriminant = (pow(b,2)-4*a*c);
  
      return discriminant;
  }
  
  void abc (void)
  {
      if (discriminant() &gt; 0)
      {
          x1real = (-b - sqrt(discriminant()))/(2*a);
          x2real = (-b + sqrt(discriminant()))/(2*a);
          x1imag = 0;
          x2imag = 0;
      }
      else
      {
          x1real = x2real = (-b) / (2*a);
          x1imag = (-b - sqrt(-discriminant())) / (2*a);
          x2imag = (-b + sqrt(-discriminant())) / (2*a);
      }
  
      return;
  } 
  input:
  4
  2   0   0
  1   3   2
  3   4   9
  1   0   1
  
  
  
  output:
  The roots of 2x^2 + 0x + 0 are:
  x = 0.0000
  The roots of 1x^2 + 3x + 2 are:
  x1 = -1.0000, x2 = -2.0000
  The roots of 3x^2 + 4x + 9 are:
  x1 = -0.6667+-2.2653i, x2 = -0.6667-0.9319i
  The roots of 1x^2 + 0x + 1 are:
  x1 = 0.0000+-1.0000i, x2 = 0.0000-1.0000i
  
  suspected output:
  The roots of 2x^2 + 0x + 0 are:
  x = 0.0000
  The roots of 1x^2 + 3x + 2 are:
  x1 = -1.0000, x2 = -2.0000
  The roots of 3x^2 + 4x + 9 are:
  x1 = -0.6667+1.5986i, x2 = -0.6667-1.5986i
  The roots of 1x^2 + 0x + 1 are:
  x1 = 0.0000+1.0000i, x2 = 0.0000-1.0000i
  </code></pre>