intelliSense: no instance of overloaded function "sqrt" matches the argument list argument types are: (double *)

897 views Asked by At

What is wrong with this code ??!!! i am making a program trying to solve quadratic equation and see this error and couldn't solve it shall i change to float or what ??

#include<stdio.h>
#include<conio.h>
#include<math.h>

void solve_quadratic(double a,double b,double c ,double *d ,double *r1,double *r2);
int main (void)
{
double x,y,z;
double root1,root2;
double desc;
printf("Enter the value of a:  ");
scanf("%lf",&x);
printf("Enter the value of b :  ");
scanf("%lf",&y);
printf("Enter the value of c :   ");
scanf("%lf",&z);

solve_quadratic(x,y,z,&desc,&root1,&root2);
if (desc<0)
{
    printf("No Result !!!");
}
else if (desc>0)
{
    printf("The value of the first root = %f \n",root1);
    printf("The value of the second root = %f  \n",root2);
}
getch();
return 0;

}

void solve_quadratic(double a,double b,double c ,double *d ,double *r1,double *r2)
{
*d=b*b-4*a*c;
if (d>=0)
{
    *r1=(-b+sqrt(d))/(2*a);
    *r2=(-b-sqrt(d))/(2*a);
}
}
1

There are 1 answers

1
ravi On BEST ANSWER
*r1=(-b+sqrt(d))/(2*a);     <<<< d is pointer not double.

You are passing pointer to double to sqrt. It should be :-

*r1=(-b+sqrt(*d))/(2*a);