# Thread: Why is this not working?

1. ## Why is this not working?

i wrote this program..sweat all over it...but its not working..can any one help me figure my mistake?

Code:
```#include <string>
#include <iostream>
#include <cmath>

using namespace std;

int QuadRoots ( double a, double b, double c, double &r1, double &r2);

int main()
{
int result = 0;
double a, b, c;
double r1,r2;

cin  >> a  >> b  >> c;

result = QuadRoots(a, b, c, r1, r2);
if (result == 0)
{
cout << "Roots: " << "r1= " << " " << "r2= "
<< endl;
}
else if(result == 1)
{
cout << "One of the root is negative";
}
else if(result == 2)
{
cout << "One of the root is 0";
}
return 0;
}

int QuadRoots ( double a, double b, double c, double &r1, double &r2)
{
int result = 0;

if(a == 0)
{
result = 2;
}
if((b*b - 4*a*c) < 0)
{
result = 1;
}
if ((a != 0) && ((b*b - 4*a*c) > 0))
{
double radical = sqrt(b*b - 4*a*c);
&r1 = (-b + radical) / (2*a);
&r2 = (-b - radical) / (2*a);
result = 0;
}
return result;
}```

2. What do you mean it isn't working? Is it producing a compile error?

3. Code:
```&r1 = (-b + radical) / (2*a);
&r2 = (-b - radical) / (2*a);```
you already passed the address when calling the function, so no need to set that equal to the address of the variable...take out the &'s and it should work fine.

4. ok so when i take the & out..the value of r1 n r2 does not appear!

5. Code:
```    if (result == 0)
{
cout << "Roots: " << "r1= " << " " << "r2= "
<< endl;
}```
be nice if you actually outputed the variables

edit: in case you dont know what i mean ....

Code:
```    if (result == 0)
{
cout << "Roots: " << "r1= " << r1 << " " << "r2= "
<< r2 << endl;
}```

6. thanx..it compiles now