C++ problem with output

Hey! So I wrote this code:

#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int a,b,c;
double x1,x2,delta;
cin>>a;
cin>>b;
cin>>c;
delta=b*b-4*a*c;
x1=(-b+sqrt(delta))/(2*a);
x2=(-b-sqrt(delta))/(2*a);
cout<<"x1="<<x1<<"x2="<<x2;
}

For some reason it only outputs "nan". Any ideas why? I tried with many inputs.
If delta is negative, the roots are imaginary.
1
2
3
4
5
6
7
    if (delta < 0)
    {
        cout << "No real roots\n";
    }
    else
        // etc.
 
Thanks pal!
Registered users can post here. Sign in or register to post.
  • 1007451581 2018-02-22
  • 8908121580 2018-02-22
  • 141161579 2018-02-22
  • 9421578 2018-02-22
  • 2826901577 2018-02-22
  • 3647361576 2018-02-22
  • 5717551575 2018-02-22
  • 523811574 2018-02-22
  • 6439871573 2018-02-22
  • 8109431572 2018-02-22
  • 8757321571 2018-02-22
  • 5265111570 2018-02-22
  • 3351351569 2018-02-22
  • 5109361568 2018-02-22
  • 4455391567 2018-02-22
  • 9091121566 2018-02-22
  • 24791565 2018-02-22
  • 2486841564 2018-02-21
  • 9847231563 2018-02-21
  • 9264681562 2018-02-21